bson

Node.js to MongoDB: find by Date

回眸只為那壹抹淺笑 提交于 2019-12-06 14:18:38
Problem with find Date from Node to MongoDB: It's been said MongoDB might not be storing a Date object, but a string, but I'm not sure how to check, or how to fix that. In my turnys.js file: exports.findNeededTurnys = function(req, handler) { console.log("findNeededTurnys"); var key; //var arg0 = {$or:[{start:{$lte:new Date()}, $where: "this.users.length == this.seats"}]}; var arg0 = {start:{$lte:new Date()}}; console.log("findNeededTurnys: arg0="+JSON.stringify(arg0)); turnydb.collection('turnys', function(err, collection) { collection.find(arg0, {safe:true}, function(err, result) { if(err)

mongo备份与恢复工具的对比与说明

断了今生、忘了曾经 提交于 2019-12-06 12:31:22
mongo备份与恢复工具的对比与说明 2015年09月06日 09:34:40 阅读数:673 Mongodb提供了mongodump/mongorestore,mongoexport/mongoimport两套机制进行数据备份和恢复,其中mongodump主要进行整库备份,mongoexport则主要进行数据集导出。 公共参数: –port arg 指定端口 -h arg 指定主机,如:127.0.0.1,也可以直接指定端口号:127.0.0.1:27017 -d arg 指定database -c arg 指定collection –dbpath arg 指定mongod的数据库文件所在路径 备份: mongodump 命令用法:mongodump [options] 特别参数: -o arg 输出的” 目录 “,不指定时,默认在执行命令的路径下创建dump目录导出 -q arg json query,此处可通过json查询,有选择性的导出数据 说明: 1.与mongorestore构成一对工具集,即由Mongodump导出的数据可由mongrestore恢复 2.mongodump可用于“热备份” 3.导出的数据是bson格式 性能:数据库中1g的数据导出后变成285M,大概8秒 mongoexport 命令用法:mongoexport [options] 特别参数: -q

Does order matter in bson_iter_find in mongo c driver

眉间皱痕 提交于 2019-12-06 04:39:16
I am using mongo c driver 1.1 with mongo version 3.0. Libbson version 1.1. I am using an iterator to look for certain fields in a document. The following code only works when "fieldA" is above "fieldB" in mongodb. If i change the order bson_iter_find returns false. if(bson_iter_find(&iterator,"fieldA")){ pintf("fieldA"); } if(bson_iter_find(&iterator,"fieldB")){ pintf("fieldB"); } In older versions of the libbson(0.4) I was able to use bson_find(), to look for fields in a doc. Is there something similar i can use in the new libbson library? Link to new libbson library https://api.mongodb.org

MongoDB Scala Driver - Rendering BSON Documents

别等时光非礼了梦想. 提交于 2019-12-05 21:28:05
We currently have a Type-Safe query language at work, this custom DSL allows us to easily write database queries that are interpreted and converted into Mongo Queries. We recently swapped over from Casbah to the new Mongo Scala Driver and rewrote our interpreter. I am however having some issues when dealing with optional values. This is an example query: dao.headOption(Order.id === orderId.some) The type stored on the Order Object is an Option so we lift the provided id into an option as well. However whenever I try to render out the generated query for debugging as well as for test cases in

mongodb part of objectid most likely to be unique

我的未来我决定 提交于 2019-12-05 20:20:35
In my app I'm letting mongo generate order id's via its ObjectId method. But in user testing we've had some concerns that the order id's are humanly 'intimidating', i.e. if you need to discuss your order with someone over the telephone, reading out 24 alphanumeric characters is a bit tedious. At the same time, I don't really want to have to store two different id's, one 'human-accessible' and one used by mongo internally. So my question is this - is there a way to choose a substring of length 6 or even 8 of the mongo objectId string that I could be fairly sure would be unique ? For example if

How can I use mongodb projections with Go and mgo?

本小妞迷上赌 提交于 2019-12-05 18:27:12
I am currently trying to extract a single object within a document array inside of mongodb. This is a sample dataset: "_id" : ObjectId("564aae61e0c4e5dddb07343b"), "name" : "The Races", "description" : "Horse races", "capacity" : 0, "open" : true, "type" : 0, "races" : [ { "_id" : ObjectId("564ab9097628ba2c6ec54423"), "race" : { "distance" : 3000, "user" : { "_id" : ObjectId("5648bdbe7628ba189e011b18"), "status" : 1, "lastName" : "Miranda", "firstName" : "Aramys" } } }, { "_id" : ObjectId("564ab9847628ba2c81f2f34a"), "bet" : { "distance" : 3000, "user" : { "_id" : ObjectId(

数据备份及恢复(mongodump/mongorestore)

别等时光非礼了梦想. 提交于 2019-12-05 18:24:52
数据备份及恢复(mongodump/mongorestore) 2019年01月17日 16:22:29 DreamLRH 阅读数 266 说明 1.mongodump创建高保真的BSON文件,mongorestore可以用其恢复数据库。对于小型数据库的备份和恢复,这两个工具非常简单和高效,但对于大型数据库的备份并不理想。 2.mongodump/mongorestore可以直接对正在运行的mongodb执行操作。 3.默认情况下,mongodump不会捕获本地数据库的内容,而只是捕获其中的document,所以占用空间较小(我试过了,占用空间也不少,原空间占用17G,备份完了37G)。不过,这也导致mongorestore恢复数据时,需要重建索引。 4.mongodump执行过程中会影响mongodb的性能。另外,即使执行结束后的一段时间性能依然会受到影响,因为读取冷数据时,会把热数据从缓存中挤出去了。 5.如果数据大于系统内存,那么查询将会导致内存溢出,从而导致page faults。不过我测试时,待备份数据17G,机器内存8G,并没有出现错误。 6.如果输出文件夹中有文件,mongodump会覆盖。 --oplog mongodump使用--oplog选项,捕获备份过程中的修改,以保障备份数据的一致性。但这个需要另外配置,涉及复制功能。本文档未使用此选项。相对应的

Mongo的备份和恢复(mongodump 和mongorestore )

耗尽温柔 提交于 2019-12-05 18:24:40
Mongo的备份和恢复(mongodump 和mongorestore ) --备份单个表 mongodump -u superuser -p 123456 --port 27017 --authenticationDatabase admin -d myTest -c d -o /backup/mongodb/myTest_d_bak_201507021701.bak --备份单个库 mongodump -u superuser -p 123456 --port 27017 --authenticationDatabase admin -d myTest -o /backup/mongodb/ --备份所有库 mongodump -u superuser -p 123456 --authenticationDatabase admin --port 27017 -o /root/bak --备份所有库推荐使用添加--oplog参数的命令,这样的备份是基于某一时间点的快照,只能用于备份全部库时才可用,单库和单表不适用: mongodump -h 127.0.0.1 --port 27017 --oplog -o /root/bak --同时,恢复时也要加上--oplogReplay参数,具体命令如下(下面是恢复单库的命令): mongorestore -d swrd -

Deserializing MongoDB BSON

核能气质少年 提交于 2019-12-05 16:35:58
I attempting to take a response from a REST service that queries an instance of MongoDB and parse the response into a Java object. The web service returns the response with a MIME type of html with a newline character separating each record that is returned (although I have the ability to adjust what the service returns). What is the easiest/most efficient way for converting the BSON response into a Java object? I have already created a template class in Java to store the data. Thanks in advance! edit: A colleague suggested to me using the MongoDB Java driver's BSON parsing utilities in the

What is the syntax for Dates in MongoDB running on MongoLab?

落花浮王杯 提交于 2019-12-05 11:02:38
Instead of ObjectId('82he921he982he82') its "_id":{"$oid":"82he921he982he82"} for object Ids, but I have no idea how to create a date value in a document on MongoLab :s If you are using one of the drivers, you create a date via that language's Date class. For instance, in Javascript (like Node.js) it would be 'new Date(11,11,11)'. If using the MongoLab REST API or admin UI you represent dates with this syntax: { "$date": "2010-10-28T23:07:11Z" } Also if an item has: "dateAdded": { "$date": "2012-07-30T15:26:15.321Z" } in one of it's entries, then you can find it by searching: { "dateAdded": {