草庐IT

document-oriented-db

全部标签

node.js - 如何在nodejs中将变量名称作为mongo db的集合名称传递

我正在使用Nodejs和mongodb,我想将一个变量传递给集合varid="someid";db.collection(id).insert("somejsondata");如果我这样做,它会给我一个错误,因为集合名称必须是一个字符串。 最佳答案 您可以使用var作为集合名称创建变量varcolName="mytest"然后对集合执行如下所有操作:db[colName].find()db[colName].rename("newName")等这将帮助您保持集合名称动态,甚至可以更新它以保持您的命令不变。希望这对您有所帮助!

ruby-on-rails - Rails3/Mongoid - 基本数据库 :seed with embedded documents

我在Rails3.1中使用MongoID。我想播种我的数据库(在开发和生产中)。我有一个嵌入了Feed的页面模型。为每个页面植入嵌入式提要的最佳方式是什么?我可以轻松地为所有页面数据播种,而不是嵌入的提要。请注意,我正在寻找这些页面/提要的实际唯一数据,而不仅仅是任意测试数据。谢谢!page.rb(模型)...embeds_many:feedsfeed.rb(模型)classFeedincludeMongoid::Documentfield:source,:type=>Stringfield:user,:type=>Stringembedded_in:page,:inverse_of=

java - Bson - 如何将 JSON 转换为 List<Document> 并将 List<Document> 转换为 JSON?

我将JavaDriver3.0与MongoDB结合使用,以便通过网络服务发送JSON。当我想将Document对象(org.bson.Document)转换为JSON时,我使用obj.toJson(),当我想将JSON转换为Document对象时,我使用Document.parse(json)。但是,当我处理文档列表时(在JSON中表示如下:[{"field1":1,...},{"field1":2,...}]),我想不出一种干净的方法来进行这些转换。到目前为止,我已经想出了这些“技巧”:从列表到JSON:我将文档列表添加为更大文档中名为“列表”的字段的值。我将这个大文档转换为JSON

mongodb - mongo3 升级后获取 DatabaseException 'not authorized for query on db.collection'(代码 = 13)

我使用免费的MongoLab,我的数据库在周末升级到Mongo3,现在我的客户端无法连接。我不断收到“未授权查询db.collection”的消息。错误。Mongolab说我应该使用Mongo3兼容的驱动程序(http://docs.mongodb.org/manual/release-notes/3.0-compatibility/#driver-compatibility-changes)。我正在使用scalaReactiveMongo客户端,版本0.11.7,它应该支持Mongo3。 最佳答案 解决方案是将“?authMode

mongodb - db.getCollectionNames() 等效于 pymongo

mongodbdb.getCollectionNames()命令将为您提供当前数据库中所有集合名称的列表。我想要使用pymongo的相同输出。我用谷歌搜索了一段时间,找不到类似的东西。这样的东西存在吗? 最佳答案 collection_names()将显示当前数据库的集合。来自文档:collection_names()Getalistofallthecollectionnamesinthisdatabase.[readmore] 关于mongodb-db.getCollectionNam

node.js - db.collectionNames 在 Node.js 中不起作用

我想检查Node.js中是否存在一个集合。我使用db.collectionNames获取数据库中的名称列表,但没有任何反应。代码:connectDB(DBURL).then(function(db){console.log('dbconnectok');db.collectionNames('test',function(err,collectionNames){console.log('getcollectionnames');if(err)console.log(err);elseconsole.log(collectionNames);});},function(err){con

java 的 DB.getCollection() 不会创建集合,即使 javadoc 是这样说的

JavaDocofDB.getCollection状态:Getsacollectionwithagivenname.Ifthecollectiondoesnotexist,anewcollectioniscreated.不过,貌似这个集合其实是后来创建的。在getCollection()之后不存在。例如,当我插入一个文档时,它就会创建。考虑一下:myCollection.getDB().getCollection("dummy").getStats()(com.mongodb.CommandResult){"serverUsed":"localhost/127.0.0.1:27801"

node.js - Mongoose 查询 : compare two values on same document

我如何使用Mongoose查询Mongo集合以查找在它们自己的两个属性之间具有特定关系的所有文档?例如,我如何查询一个characters集合来找到所有那些currentHitPoints值小于它们的maximumHitPoints值的字符?或者所有那些currentPledgedMoney少于他们的pledgeGoal的项目?我试过这样的事情:mongoose.model('Character').find({player:_currentPlayer}).where('status.currentHitpoints').lt('status.maximumHitpoints').e

javascript - meteor JS : Client not getting data from Mongo DB

我已经开始学习MeteorJS并制作了一个示例应用程序。我在mongoDB中有一个集合,我想在客户端中查看该集合这是我的服务器代码(文件在/libs)newColl=newMeteor.Collection("newColl");if(Meteor.isServer){Meteor.publish('newCollectionData',function(){console.log(newColl.find().fetch());returnnewColl.find();});}这是我的客户端代码(文件在/client)Meteor.subscribe("newCollectionDa

mongodb - 如何启用 mongodb cli pretty-print ? - db.col.find().pretty() 不工作

使用mongov2.4.5shell,db.col.find().pretty()在osx控制台或linuxubuntu12.04bash上对我来说打印效果不佳。使用和不使用pretty()的输出没有区别>db.people.find(){"_id":ObjectId("520d293752cfe6ece5d3fd77"),"name":"Andrew"}{"_id":ObjectId("520e448b77803f8f15fcfedb"),"name":"Amy"}>>db.people.find().pretty(){"_id":ObjectId("520d293752cfe6ec