mongodb-query

Possible to compare date strings in mongodb?

被刻印的时光 ゝ 提交于 2019-12-11 01:39:49
问题 I have a collection that contains documents with a date attribute like so: { title: "whatever", created: ISODate("2013-05-27T03:36:50Z") } I would like to select records that were created on a certain day. I was hoping I could use toDateString() and compare the values but when I do a search like the one below: db.myCollection.find({ 'created.toDateString()': new Date('05/27/2013').toDateString() }).pretty() But this does not work. Is there any way to do what I am attempting above? 回答1: If you

Morphia - using hasAllOf and hasThisElement together

坚强是说给别人听的谎言 提交于 2019-12-11 01:22:51
问题 I have a mongo collection named 'comment' which has documents which have a structure similar to this : { "_id" : ObjectId("9873214jkhdkfjdsf8324"), "nm" : "test", "sts" : 1, "updby" : NumberLong(0), "tags" : [ { "name" : "women", "rank" : 1, "type" : 3 }, { "name" : "men", "rank" : 1 }, { "name" : "clothing", "rank" : 2, "type" : 1 } ] I want to query the collection using a mongo query which would look like this : db.comment.find({"tags":{ $all:[ {"$elemMatch":{"name" : "women", "type" : 3}},

How to filter data between two times from hh:mm to hh:mm in mongoDB

我的梦境 提交于 2019-12-11 01:17:28
问题 Mongoose var filter = {}; filter.strBillDate = { "$gte": new Date(req.params.fromdate), "$lt": new Date(req.params.todate) }; return Sales .aggregate([{ $match: filter }, { "$project": { "strBillNumber": 1, "strBillAmt": 1, "store_id": 1, "strBillDate": 1, "hourPart": { "$hour": "$strBillDate" }, "minutePart": { "$minute": "$strBillDate" }, } }, { "$match": { "hourPart": { "$gte": fromhour, "$lte": tohour } } }]) .exec(function(err, salesdata) { if (!err) { return res.send(salesdata); } });

dbref command in mongodb

情到浓时终转凉″ 提交于 2019-12-11 01:14:06
问题 I am newbie to mongodb. I need to do a query by reference two collections using dbref and need to query particular fields. comments collection { uid:12345, pid:444, comment="blah" }, { uid:12345, pid:888, comment="asdf" }, { uid:99999, pid:444, comment="qwer" } users collection { uid:12345, name:"john" }, { uid:99999, name:"mia" } May I know the command how to insert these collections in mongodb by adding reference between two collections usind dbref? comments in uid must refer the users uid.

Find documents with arrays that contain a document with a particular field

Deadly 提交于 2019-12-11 00:59:20
问题 I want to find only documents that have all 'docs.foo' present in a array. In my example I should get only _id: 2 result: { _id : 1, docs : [ { bar : 2}, { foo : 3, bar : 3} ] }, { _id : 2, docs : [ { foo : 2, bar : 2}, { foo : 3, bar : 3} ] } I thought about something like: db.collection.find({'docs.foo': {$nin: [$exists: false]}}) but couldn't make it work. 回答1: Using the $where operator. db.collection.find(function() { return this.docs.length === this.docs.filter(function(doc) { return

Get unique number of reservation based on dates

天涯浪子 提交于 2019-12-11 00:58:54
问题 How can I get unique booking counter? Like If I pass from date as "1970-01-01" and to date as "1970-01-05" then it will return me only 1. Because there is two booking but that's on different date (One is from 1970-01-01 to 1970-01-02 and another is from "1970-01-03" to "1970-01-05"). Reserved array contains all the booked rooms with from to to dates Here is my data: [ { "_id": "5c0a17013d8ca91bf4ee7885", "name": "ABC", "reserved": [ { "from": "1970-01-01", "to": "1970-01-02", "isCompleted":

How to implement data encryption at rest for MongoDB Community Edition?

*爱你&永不变心* 提交于 2019-12-11 00:55:24
问题 I've gone through MongoDB docs that explain how to configure encryption which is available in MongoDB Enterprise only. How to implement data at rest in MongoDB Community Edition v3.4? 回答1: I was asking the same question to myself just few month ago. This is a list of options I have found so far: encrypt storage volumes on the file system level. It is what Atlas offers, and most of cloud providers support: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html, https://docs

performing priority query in mongo

微笑、不失礼 提交于 2019-12-11 00:39:11
问题 sample document : {"name":"John", "age":35, "address":".....",.....} Employees whose join_month=3 is priority 1 Employees whose address contains the string "Avenue" is priority 2 Employees whose address contains the string "Street" is priority 3 Employees whose address contains the string "Road" is priority 4 As of now, I'm at this stage: db.collection.aggregate([ { "$match": { "$or": [ { "join_month": 3 }, { "address": /.*Avenue.*/i }, { "address": /.*Street.*/i }, { "address": /.*Road.*/i }

How can i calculate total positive ,total negative price and sum using Node.js and Mongoose

大兔子大兔子 提交于 2019-12-11 00:08:39
问题 i have written query for getting all user records exports.index = function(req, res) { Userdata.find(function(err, userdatas) { if (err) { return handleError(res, err); } console.log(userdatas); }); }; console i am getting below documents { "_id" : ObjectId("584bc9ba420a6b189c510af6"), "user_id" : 1, "price" : 2000.0, "type" : "credit", }, { "_id" : ObjectId("584bc9ba420a6b189c510af7"), "user_id" : 1, "price" : -1000.0, "type" : "credit", }, { "_id" : ObjectId("584bc9ba420a6b189c510af8"),

MongoDB Number Field will not insert or update with the number that I input

ぃ、小莉子 提交于 2019-12-10 23:16:52
问题 this is my problem: db.Group6391102Bounds.insert({ bound:"latest",id:138548488276343678,complete:false}) db.Group6391102Bounds.find() { "_id" : ObjectId("5297d9e5ef9f659b82271617"), "bound" : "earliest", "id" : 138548488276343680, "complete" : false } { "_id" : ObjectId("5297dc28b2d702ea878b540d"), "bound" : "latest", "id" : 138548488276343680, "complete" : false } db.Group6391102Bounds.insert({ bound:"middle",id:138548488276343678,complete:false}) db.Group6391102Bounds.find() { "_id" :