mongodb-query

mongodb query multiple pairs using $in

蓝咒 提交于 2019-12-11 17:28:14
问题 I have a collection names with data (_id is omitted): {first:"John", last:"Smith"}, {first:"Alice", last:"Johnson"}, {first:"Bob", last:"Williams"}, ... and {first, last} is a unique index. I want to find a lot of names in names like: db.names.find({$or: [{first:"Alice", last:"Brown"}, {first:"Bob", last:"White"}, ...]} Can I use $in instead of $or to simplify this query? === I know in MySQL this following query: SELECT * FROM names WHERE (first = 'Alice' AND last = 'Brown') OR (first = 'Bob'

How to $filter where condition is matched against an array?

半城伤御伤魂 提交于 2019-12-11 17:25:19
问题 after $lookup i will get a join named lastViewed like this: { "_id" : "5955ea4fd8099718330ab191" lastViewed: [ { "_id" : ObjectId("595218a7d346d27fb0bc1705"), "userId" : ObjectId("58c796d4344b9da4dfbe027b"), "groupId" : ObjectId("5955ea4fd8099718330ab191"), "lastViewedTime" : ISODate("2017-06-19T09:39:07.374Z") }, { "_id" : ObjectId("595218a7d346d27fb0bc1764"), "userId" : ObjectId("58c796d4344b9da4dfbe027b"), "groupId" : ObjectId("5955ea4fd8099718330ab162"), "lastViewedTime" : ISODate("2017

how to store & update matching values based on $OR operator, in mongodb?

走远了吗. 提交于 2019-12-11 17:18:36
问题 My collections contain nested document and I'm trying to get "Text" present in any of the nested fields such as: var rerun = { $or: [ {"code_exception.java_40.code.Text": { $exists : true, $ne : "" } },//13816 {"code_exception.java_15.code.Text":{ $exists : true, $ne : ""} },//13485 {"code_exception.java_10.code.Text":{ $exists : true, $ne : ""} },//12994 {"code_exception.java_2.code.Text": { $exists : true, $ne : ""} },//13294 {"code_exception.java_4.code.Text": { $exists : true, $ne : ""} }

Query for documents where array size is greater than 1

与世无争的帅哥 提交于 2019-12-11 16:57:12
问题 I have a MongoDB collection with documents in the following format: { "_id" : ObjectId("4e8ae86d08101908e1000001"), "name" : ["Name"], "zipcode" : ["2223"] } { "_id" : ObjectId("4e8ae86d08101908e1000002"), "name" : ["Another ", "Name"], "zipcode" : ["2224"] } I can currently get documents that match a specific array size: db.accommodations.find({ name : { $size : 2 }}) This correctly returns the documents with 2 elements in the name array. However, I can't do a $gt command to return all

Mongodb C# complex query

岁酱吖の 提交于 2019-12-11 16:34:40
问题 I'm kind of new to c# mongodb driver. I have a collection which contains documents with following structure. { _id : 5a424d61f5213516a0249323, email : abc@gmail.com, applications : [ { applicationId : 5a3b54723629c20df8bcae8d, applicationStatus: "Open", type : "Private", category : "Tech" }, { applicationId : 5a3b54723629c20df8bcaeasd, applicationStatus: "Close", type : "Public", category : "Agri" }, { applicationId : 5a3b54723629c20df8bcajkl, applicationStatus: "Open", type : "Public",

Populate to the deep level using $lookup mongodb

帅比萌擦擦* 提交于 2019-12-11 16:24:34
问题 I am using $lookup to join two collections and get data from below query: let condition = {status:{$ne:config.PROJECT_STATUS.completed}, assignId:mongoose.Types.ObjectId(req.params.id)}; Project.aggregate([ { $match: condition }, { "$group":{ "_id": "$_id" } }, { "$lookup": { "from": "worksheets", "let": { "projectId": "$_id" }, "pipeline": [ { "$match": { "$expr": { "$eq": [ "$projectId", "$$projectId" ] }}}, { "$group": {_id:"$projectId", totalHours:{"$sum": "$hours"}}}, { "$lookup": {

Find one document from whole collection, with one specific value nested inside multiple embedded sub documents

怎甘沉沦 提交于 2019-12-11 16:23:59
问题 I need to find one document which matches the unique criteria from query. Below is example data - Please note we have to find an email from the document where "verificationCode" : "4146" Let me know if you need me to explain my question in more details. { "_id": ObjectId("58dc5b9f3107602dbaba1280"), "email": "test1@gmail.com", "password": "password", "userName": "test1", "companyName": "W company", "apiKey": "JSAD&unjSAD7821SADnosad&", "apiCallCount": 0, "buildings": [ { "_id": ObjectId(

node js nested loop results finally push to single array

穿精又带淫゛_ 提交于 2019-12-11 16:17:20
问题 i will get the Array of Answers but how to get the Answered users info; the flow is Get List of Posts , Post User Info , Post User Followers Count , Post Likes Count , Login User Liked The Post True or False , Answers , Answered User Info and Answered User Followers Count exports.GetPostList = function(req, res) { var SkipCoun = 0; SkipCoun = parseInt(req.params.Limit) * 10; QuestionsPostModel.QuestionsPostType.find({}, {} , {sort:{createdAt : -1}, skip: SkipCoun, limit: 10 }, function(err,

insert new inner object into existing object mongodb using php

南笙酒味 提交于 2019-12-11 16:07:49
问题 I have the following document in my mongo collection {"_id":"5a9e97557cf28c1c2d00003d", "user_id":"avi12", "name":"Avinash", "Friends":{ "avi12":{ "From":"avi12", "To":"chandu", "Friend_status":"pending", "Time":1520342869, "requestid":"s_avi12_first" }, "second_user":{ "From":"avi122", "To":"chandu2", "Friend_status":"pending2", "Time":1520342869, "requestid":"2s_avi12_first" } } } I want to inset new object ("Third user") into Friends object . I have tried the following code... $update

Remove documents from a MongoDB collection based on “time” of a Date field

本小妞迷上赌 提交于 2019-12-11 16:02:57
问题 I have a collection which stores documents with the following structure: { "_id" : NumberLong(-6225637853094968071), "Id" : "1585534", "Type" : NumberInt(42), "InDate" : ISODate("2017-10-05T18:30:00.000+0000"), } { "_id" : NumberLong(-622563784353458071), "Id" : "15832422", "Type" : NumberInt(42), "InDate" : ISODate("2017-10-06T00:00:00.000+0000"), } I want to delete all documents with a particular "Id" and "Type" where the "InDate" field has time 18:30:00.000+0000 . I tried using this query: