mongodb-query

Retrieve multiple queried elements in an object array in MongoDB collection

妖精的绣舞 提交于 2020-01-16 12:45:25
问题 I want to find all zone data with "AHU":"C". First, I query without projection and get these. > db.buildings.find({"zone.AHU": "C"}).pretty() { "_id" : ObjectId("5aba4460a042dc4a2fdf26cd"), "name" : "Test Street", "coordinate" : [ 12, 31 ], "yearlyEnergyCost" : 1444, "zone" : [ { "name" : "AHU-C-Z2", "_id" : ObjectId("5aba4460a042dc4a2fdf26ce"), "AHU" : "C", "precooling" : [ ], "subZone" : [ ] }, { "name" : "AHU-D-Z1", "_id" : ObjectId("5abc7528100730697163a3ab"), "AHU" : "D", "precooling" :

Retrieve multiple queried elements in an object array in MongoDB collection

谁说我不能喝 提交于 2020-01-16 12:45:07
问题 I want to find all zone data with "AHU":"C". First, I query without projection and get these. > db.buildings.find({"zone.AHU": "C"}).pretty() { "_id" : ObjectId("5aba4460a042dc4a2fdf26cd"), "name" : "Test Street", "coordinate" : [ 12, 31 ], "yearlyEnergyCost" : 1444, "zone" : [ { "name" : "AHU-C-Z2", "_id" : ObjectId("5aba4460a042dc4a2fdf26ce"), "AHU" : "C", "precooling" : [ ], "subZone" : [ ] }, { "name" : "AHU-D-Z1", "_id" : ObjectId("5abc7528100730697163a3ab"), "AHU" : "D", "precooling" :

Retrieve multiple queried elements in an object array in MongoDB collection

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-16 12:44:48
问题 I want to find all zone data with "AHU":"C". First, I query without projection and get these. > db.buildings.find({"zone.AHU": "C"}).pretty() { "_id" : ObjectId("5aba4460a042dc4a2fdf26cd"), "name" : "Test Street", "coordinate" : [ 12, 31 ], "yearlyEnergyCost" : 1444, "zone" : [ { "name" : "AHU-C-Z2", "_id" : ObjectId("5aba4460a042dc4a2fdf26ce"), "AHU" : "C", "precooling" : [ ], "subZone" : [ ] }, { "name" : "AHU-D-Z1", "_id" : ObjectId("5abc7528100730697163a3ab"), "AHU" : "D", "precooling" :

Parent.save() not working when sub document / deeply nested document is modified

好久不见. 提交于 2020-01-16 08:41:39
问题 I find my document from whole collection like this: const account = await Account.findOne({ "buildings.gateways.devices.verificationCode": code }) const buildings = account.buildings const gateways = buildings[0].gateways; const devices = gateways[0].devices; const device = _.filter(devices, d => d.verificationCode === code); now I want to change one of the property "patientLastName" and then save the whole document. I am doing as below. device.patientLastName = lastName; const updated =

Querying for array in embedded list

谁都会走 提交于 2020-01-16 05:21:06
问题 Supposed I have a mongo document that looks similar to the following: { 'foo':1 'listOfLists' : [ [1,2],[3,4] ] } (Yes I am aware this isn't how it "really" looks but it should be simple enough for explanation purposes.) If I wanted to write a query that would check to see if the listsOfLists list object contains the combination of [3,4], how could I go about doing that? Could I do something like collection.find({'listsOfLists' : {'$elemMatch' : [3,4] } }) 回答1: collection.find({ 'listsOfLists

MongoDB finding nested objects that meet criteria

你。 提交于 2020-01-16 05:04:13
问题 I have a MongoDB document that is structured similar to the structure below follows. I am searching based on people.search_columns.surname and people.columns.givenname. So for example, when I search for the given name of "Valentine", I want to get the document back, but Nicholas Barsaloux should not be included. Data structure: [_id] => MongoId Object ( [$id] => 53b1b1ab72f4f852140dbdc9 ) [name] => People From 1921 [people] => Array ( [0] => Array ( [name] => Barada, Valentine [search_columns

push item in sub document

断了今生、忘了曾经 提交于 2020-01-15 12:18:12
问题 I have simple collection. I want to push item in question, but it gives an exception.How can I resolve it ? /* 1 */ my collection data { "_id" : ObjectId("557e8c93a6df1a22041e0879"), "QuestionCount" : 2.0000000000000000, "Questions" : [ { "_id" : ObjectId("557e8c9ba6df1a22041e087a"), "DataSource" : [], "DataSourceItemCount" : NumberLong(0) }, { "_id" : ObjectId("557e8c9fa6df1a22041e087b"), "DataSource" : [], "DataSourceItemCount" : NumberLong(0) } ], "Name" : "er" } ( id

Why Mongo query for null filters in FETCH after performing IXSCAN

Deadly 提交于 2020-01-15 11:53:37
问题 According to Mongo Documentation, The { item : null } query matches documents that either contain the item field whose value is null or that do not contain the item field. I can't find documentation for this, but as far as I can tell, both cases (value is null or field is missing) are stored in the index as null . So if I do db.orders.createIndex({item: 1}) and then db.orders.find({item: null}) , I would expect an IXSCAN to find all documents that either contain the item field whose value is

Why Mongo query for null filters in FETCH after performing IXSCAN

南楼画角 提交于 2020-01-15 11:52:59
问题 According to Mongo Documentation, The { item : null } query matches documents that either contain the item field whose value is null or that do not contain the item field. I can't find documentation for this, but as far as I can tell, both cases (value is null or field is missing) are stored in the index as null . So if I do db.orders.createIndex({item: 1}) and then db.orders.find({item: null}) , I would expect an IXSCAN to find all documents that either contain the item field whose value is

How do I conditionally restart the promise chain from the beginning?

拟墨画扇 提交于 2020-01-15 11:43:07
问题 I am trying to implement a simple raffling system where I do a GET /test which returns a random user who (1) hasn't won the raffle previously and (2)registered in the past hour. In Mongo, there may be multiple documents associated with a user since the user can sign up for multiple subjects. For example {id: 1, name: 'John', subject: 'math',...} and {id: 1, name: 'John', subject: 'english',...} . If John gets picked for the raffle for math, then he will be ineligible for all subsequent