mongodb-query

Mongodb $subtract document value from the next one

心已入冬 提交于 2019-12-12 05:29:08
问题 I have a collection of documents as below. Example of my collection documents { "_id" : 1, "_DeviceName" : "Main Panel", "_Timestamp" : ISODate("2017-08-04T23:15:00.000+03:00"), "_LocationID" : ObjectId("598459e86b41c036f051217c"), "Meters" : { "gasmeter" : 1000.0, }}, { "_id" : 2, "_DeviceName" : "Main Panel", "_Timestamp" : ISODate("2017-08-04T23:15:00.000+03:00"), "_LocationID" : ObjectId("598459e86b41c036f051217c"), "Meters" : { "gasmeter" : 1007.0, }}, { "_id" : 3, "_DeviceName" : "Main

MongoDB groupby distinct sort together

那年仲夏 提交于 2019-12-12 05:18:20
问题 i have mongodb 1 collections structure like this- { "_id" : ObjectId("54d34cb314aa06781400081b"), "entity_id" : NumberInt(440), "year" : NumberInt(2011), } { "_id" : ObjectId("54d34cb314aa06781400081e"), "entity_id" : NumberInt(488), "year" : NumberInt(2007), } { "_id" : ObjectId("54d34cb314aa06781400081f"), "entity_id" : NumberInt(488), "year" : NumberInt(2008), } { "_id" : ObjectId("54d34cb314aa067814000820"), "entity_id" : NumberInt(488), "year" : NumberInt(2009), } { "_id" : ObjectId(

Mongoose - increment a field value in nested array

僤鯓⒐⒋嵵緔 提交于 2019-12-12 05:17:45
问题 I'm new to Mongoose and MongoDB and am trying to implement a scenario where I have to update a field value residing in a nested array. For example, my DB entry is as follows: { "_id" : ObjectId("581999ecf97860b77c1625f6"), // this is userID "username" : "test", "__v" : 0, "polls" : [ { "url" : "xxxx", "question" : "city or united", "_id" : ObjectId("581999ec3ba2b15ad7fbcd50"), //this is questionID "option" : [ { "votes" : 0, "value" : "city", "_id" : ObjectId("581999ec3ba2b15ad7fbcd52") /

Mongodb Schema for Posts and Shares

痴心易碎 提交于 2019-12-12 04:54:28
问题 I am new to mongodb NoSQL concept and stuck at point where I am unable to take a decision for modelling the schema that could best serve my purpose. I need to design schema in such a way that I have my end result as Posts and Shares sorted by time . For this I considered two options: Option 1: Different Collection for Posts and Share as: Schema for Post collection : var postSchema = mongoose.Schema({ postText: String, postedBy: String, privacy: Number, updatedOn: { type: Date, default: Date

Count and Aggregate in MongoDB

…衆ロ難τιáo~ 提交于 2019-12-12 04:51:51
问题 I have mongodb collection whose structure is as follows :- { "_id" : "mongo", "log" : [ { "ts" : ISODate("2011-02-10T01:20:49Z"), "visitorId" : "25850661" }, { "ts" : ISODate("2014-11-01T14:35:05Z"), "visitorId" : NumberLong(278571823) }, { "ts" : ISODate("2014-11-01T14:37:56Z"), "visitorId" : NumberLong(0) }, { "ts" : ISODate("2014-11-04T06:23:48Z"), "visitorId" : NumberLong(225200092) }, { "ts" : ISODate("2014-11-04T06:25:44Z"), "visitorId" : NumberLong(225200092) } ], "uts" : ISODate("2014

mongo db map reduce sum results as integer

喜你入骨 提交于 2019-12-12 04:48:56
问题 My collections seems like this { "bet_session_id": ObjectId("51a60cba6ef215d019000299"), "date": ISODate("2013-05-29T14:13:14.572Z"), "player_items": [ { "chip": NumberInt(1), "item": "x14", "ratio": NumberInt(35), "total_win": NumberInt(0) }, { "chip": NumberInt(1), "item": "x15", "ratio": NumberInt(35), "total_win": NumberInt(36) }, { "chip": NumberInt(1), "item": "121511141013", "ratio": NumberInt(5), "total_win": NumberInt(6) }, ], "user_id": "7876010", } , { "bet_session_id": ObjectId(

MongoDB fulltext search not using index

北战南征 提交于 2019-12-12 04:44:35
问题 We use mongoDB fulltext search to find products in our database. Unfortunately it is incredible slow. The collection contains 89.114.052 documents and I have the suspicion, that the full text index is not used. Performing a search with explain(), nscannedObjects returns 133212. Shouldn't this be 0 if an index is used? My index: { "v" : 1, "key" : { "_fts" : "text", "_ftsx" : 1 }, "name" : "textIndex", "ns" : "search.products", "weights" : { "brand" : 1, "desc" : 1, "ean" : 1, "name" : 3,

How to exclude the _id field while retrieving and displaying data from MongoDB using C#

﹥>﹥吖頭↗ 提交于 2019-12-12 04:37:49
问题 How do i exclude the _id field from the set of fields returned in C#, there are posts on this website that mention of the .include() and .exclude() methods but those methods are not present in my case. below is the code where 'secondary' is a field in the outer document which is an array and '.amount' is the field nested within the 'secondary' array ( like a nested document ). Can someone help me out with this please..! var fields = "secondary.amount"; foreach (var document in collection

Retrieving object from an array using '$filter' along with all other fields

孤者浪人 提交于 2019-12-12 04:32:24
问题 In my product catalog there are items like this one: [ { "title": "A great Item", "ltitle": "a great item", "brand": { "name": "MyBrand" }, "description": [ { "lang": "en-en", "full": "<p>Super great item bla bla bla super great bla bla</p>", "short": "Super great item..." }, { "lang": "es-es", "full": "<p>Producto de muy alta calidad bla bla bla alta calidad etc</p>", "short": "Producto de muy..." } ] }, ... ] I've been reading about $elemMatch but I'm not sure if that's what I'm looking for

Mongodb: Combine $in and $nin

情到浓时终转凉″ 提交于 2019-12-12 04:25:15
问题 In my collection posts I've documents like this [{ _id : ObjectId("post-object-id"), title : 'Post #1', category_id : ObjectId("category-object-id") }] I need to make some queries where I those a range of posts based on their category_id (can be multiple ids) but exclude some of them. I've tried with the query (in shell): db.posts.find({$and: [ {_id: { $nin : ['ObjectId("post-object-id")']}}, {category_id : { $in : ['ObjectId("category-object-id")']}} ]}) I returns 0 if count(). However, if I