mongodb-query

How to combine AND with OR in mongoose?

血红的双手。 提交于 2019-12-25 08:00:16
问题 I realized that when in node.js I build a query such as: if (hashtagsInput != undefined) { var hashtags = hashtagsInput.split(","); for(var i=0; i<hashtags.length; i++) { query = query.or([{ 'hashtags': hashtags[i] }]); } } if (friends != undefined) { var friendsSplitted = friends.split(","); for(var i=0; i<friendsSplitted.length; i++) { query = query.or([{ 'facebook_username': friendsSplitted[i] }]); } } then the query is: ..., '$or': [ { hashtags: 'test1' }, { hashtags: 'test2' }, {

How to convert mongoDB Query in php?

吃可爱长大的小学妹 提交于 2019-12-25 08:00:01
问题 I am facing a problem to convert a mongoDB query into php This is my mongoDB query db.contact_facts.mapReduce( function() { var k = new Date(this.date); k.setHours(0); k.setMinutes(0); k.setSeconds(0); k.setMilliseconds(0); emit({idM:this.idMailing, fact:this.fact, year:k.getFullYear(), month:k.getMonth(), day:k.getDate() }, 1); }, function (key, values) { return Array.sum(values); }, { query: { date: { $gt: ISODate('2016-09-20') } }, out: { reduce: "contact_fact_stats2"}, } ); I am facing a

Find a value in array

女生的网名这么多〃 提交于 2019-12-25 07:58:15
问题 So my collection is something like: [ {"name": "one", "jobs": ["1","2","3","4","5"]}, {"name": "two", "jobs": ["6","7","8","9","10"]}, {"name": "three", "jobs": ["11","12","13","14","15"]}, ] And I want to create a query to find the name based on the value from jobs . So if jobs=2 , the name should be one ; if jobs=9 , the name should be two ; if jobs=13 , the name should be three . What do i put in the db.collection.find({ ?? }) Thanks. 回答1: Just complementing the other answer, if you wanna

Unable to compute average time

我们两清 提交于 2019-12-25 07:47:46
问题 3 days old into MongoDB, and I am not finding it very fluid. I am simply trying to compute the average time for a field but I keep running into all sorts of problems. Here is my code: db.results.group({ key:{"profile.Zend_Http_Client_Adapter_Socket::read==>fgets":{$exists:true}}, initial: {count: 0, total:0}, reduce: function(doc, out){ out.count++; out.total += doc."profile.Zend_Http_Client_Adapter_Socket::read==>fgets.wt"; }, finalize: function(out){ out.avg = out.total/out.count; } }); The

MongoDB search by DateTime type not working

好久不见. 提交于 2019-12-25 07:17:06
问题 Hi Im new to Mongo DB and trying to start with it, i created a collection and inserted this document into it { "_id" : ObjectId("574ad7c42368e58f8c07a47d"), "id" : 10000, "BookieId" : 1, "EventBookieId" : null, "LeagueId" : 214, "LeagueNameId" : 4571, "Team1Id" : 435, "Team1NameId" : null, "Team2Id" : 430, "Team2NameId" : null, "EventDateTime" : "2013-09-14T14:00:00", "isNew" : true, "CountryId" : 36, "isCountry" : true, "isLeague" : true, "Gameid" : null, "Reversed" : false, "eventId" :

Mongo: If any array position matches single query

怎甘沉沦 提交于 2019-12-25 06:58:08
问题 Assuming this data structure: { "title": "Foo bar", "username": "jackwreid" }, { "title": "Bish bosh", "username": "lizziebump" }, { "title": "Ham nam", "username": "lizziebump" }, { "title": "Blub blub", "username": "jvarn" } And assuming var userFollowing = ["lizziebump", "jackwreid"] How would I do a db.posts.find() for posts where the username matches any of the contents of the userFollowing array? I'm trying to build a query that returns posts by users in the current user's following

How to calculate average per day field using MongoDB?

爱⌒轻易说出口 提交于 2019-12-25 06:27:28
问题 I have to calculate per day average of collection filed. I created one query on per minute basis. Now I want to convert this query in per day average. My per minute query as follows db.voltage.aggregate( { $unwind: { path:"$KeyValues", includeArrayIndex:"arrayIndex", preserveNullAndEmptyArrays:true } }, { $project: { timestamp:{ "$add":["$EventTS",{"$multiply":[60000,"$arrayIndex"]}] } , "RVoltage":"$KeyValues.RVoltage", arrayIndex:1, } }, { $match: { $and: [ {RVoltage: {$ne: null}} ] } } );

Mongodb count with queries have poor performance

十年热恋 提交于 2019-12-25 05:57:08
问题 Counting the number of records in a collection that is matched by a query even on an indexed field takes too much time. For example lets say there is a collection consists of 10000 records, and there is an index on the creationDate field of this collection. Getting the last ten records from the collection is faster than counting the number of records created on the last day. It takes more than 5 seconds, sometimes even up to 70 seconds to return the result of the count query. Do you have any

Mongodb count with queries have poor performance

断了今生、忘了曾经 提交于 2019-12-25 05:57:03
问题 Counting the number of records in a collection that is matched by a query even on an indexed field takes too much time. For example lets say there is a collection consists of 10000 records, and there is an index on the creationDate field of this collection. Getting the last ten records from the collection is faster than counting the number of records created on the last day. It takes more than 5 seconds, sometimes even up to 70 seconds to return the result of the count query. Do you have any

Using multiple $lookup with aggregation in mongodb

廉价感情. 提交于 2019-12-25 05:07:07
问题 I have three collections, _project - It contains all the projects _build - It contains all the builds and every build must belong to a project _build.details - It contains ads which must belong to an adset and each adset must belongs to a campaign and each campaign must belongs to a build. _project document structure: { "_id" : ObjectId("58d8c501be2bee2bc0b3b081"), "CreatedBy" : ObjectId("58c801c606f72508d87421c6"), .... .... },... _build document structure: { "_id" : ObjectId(