mongodb-query

error in monogdb “errmsg” : "WiredTigerIndex::insert: key too large to index, failing

瘦欲@ 提交于 2020-01-03 17:12:43
问题 I'm creating a index in mongo: db.table.createIndex({"chr" : 1, "Start" : 1, "End" : 1, "Ref" : 1, "Alt" : 1}) It runs for some time and gives an error msg: error in monogdb "errmsg" : "WiredTigerIndex::insert: key too large to index, failing How do I fix this error? 回答1: In MongoDB, since 2.6, the total size of an index entry must be less than 1024 bytes. Documentation here In other terms, at least one of your documents has a large value in one of the field you are trying to index. It's not

MongoDB - Check if value exists for a field in a document

独自空忆成欢 提交于 2020-01-03 10:47:14
问题 I have a collection where the document looks like below: /* 0 */ { "_id" : ObjectId("5320b1c723bc746084fa7107"), "channels" : [ 3, 4 ] } /* 1 */ { "_id" : ObjectId("5320b1c723bc746084fa7107"), "channels" : [ ] } I want to form a query such that I want all documents where channels has some value and is not empty. I tried this: db.event_copy.find({"channels":{$exists:true}}) But that will still return me the documents with no values in channel. 回答1: You need the $size operator. To find

Find exactly match array or having all value of array in MongoDb

折月煮酒 提交于 2020-01-03 04:56:05
问题 I have collection entry like that [ { shape : [{id:1,status:true},{id:2,status:false}] }, { shape : [{id:1,status:true}] } ] I want to fetch data which exactly match array , means contain all ele. of array. Ex. where shape.id = [1,2] / [ {id: [1,2] } ] (any one is prefer) then it should return only [ { shape : [{id:1,status:true},{id:2,status:false}] } ] So help me if is there any native mongodb query . Thanks --ND 回答1: Here is much simpler query; db.shapes.find({'shape.id':{$all:[1,2]},shape

Getting the required documents from both the collections in one query in MongoDB-3.2.7

瘦欲@ 提交于 2020-01-03 04:25:52
问题 I have two collections like below in MongoDB. lookupcol1 { "_id" : 1, "sku" : "abc", description: "product 1", "instock" : 120, "groupId":100100}, { "_id" : 2, "sku" : "def", description: "product 2", "instock" : 80,"groupId":100100 }, { "_id" : 3, "sku" : "ijk", description: "product 3", "instock" : 60 }, { "_id" : 4, "sku" : "jkl",description: "product 4", "instock" : 70 }, { "_id" : 5, "sku": null, description: "Incomplete", "groupId":100100 }, { "_id" : 6 } lookupcol2 { "_id" : 12, "sku"

mongo-go-driver aggregate query always return “Current”: null

[亡魂溺海] 提交于 2020-01-03 04:01:13
问题 I want to sum a field by using pipeline := []bson.M{ bson.M{"$group": bson.M{ "_id": "", "count": bson.M{ "$sum": 1}}} } ctx, _ := context.WithTimeout(context.Background(), 5*time.Second) result, err := collection.Aggregate(ctx, pipeline) but it always return "Current": null Any solution? 回答1: First, Collection.Aggregate() returns a mongo.Cursor, not the "direct" result. You have to iterate over the cursor to get the result documents (e.g. with Cursor.Next() and Cursor.Decode()), or use

How to find the fhe size of the specific Document in MonogoDB Collection?

删除回忆录丶 提交于 2020-01-03 02:21:06
问题 I have 100k documents in an MonoDB Collection, the document({id : '789736363828292'}) has 20k Documents/Records. I would like find the memory utilized by that particular document. Please help me to find the memory size in MB in MongoDB console. 回答1: You can use Object.bsonsize in MongoShell which will return a BSON size (in bytes ) of one document. Try Object.bsonsize(db.col.findOne({id : '789736363828292'})) 来源: https://stackoverflow.com/questions/48960694/how-to-find-the-fhe-size-of-the

MongoDB retrieve only matching sub documents from a document with c#

99封情书 提交于 2020-01-03 02:00:32
问题 I want the following query below to only return those sub documents from the empActivity array where the Stamp field in every sub document matches the Stamp value in the query. empId and empActivity are the outer level fields with empActivity having embedded documents. db.emp_activity.find({$and : [{"empId" : "999"}, {"empActivity.Stamp" : { $lte : ISODate("2015-01-09T12:33:39.927Z")}}]}) The problem is that it also returns all the sub documents that dont match the date in the query, apart

Node.js and MongoDB Time Zone Issue UTC not being converted correctly by driver?

ぐ巨炮叔叔 提交于 2020-01-02 23:05:20
问题 I have a strange thing occurring and I hope someone can point out what i am missing. In MongoDB I have a field DT that is of Type Date An example of what the date looks like in MongoDB is 2014-10-01 10:28:04.329-04:00 When I query MongoDB from Node.js using MongoClient, Node.js is returning this: 2014-10-01T14:28:04.329Z As i understand it the driver is suppose to convert UTC to local time. In my case it should be Eastern Time (EDT). Why would Node be adding 4 hours instead? I am loading the

How to dynamically build mongodb query

两盒软妹~` 提交于 2020-01-02 16:07:41
问题 I have a match expression in a mongodb aggregation. There are 3 fields that are included in the match but they don't all always contain data. I only want to include the fields in the match if the field isn't empty. This is what the match looks like if all fields have data but for example, if the array used for studentGradeLevels is empty, then I don't want to include it or I want the query to still return data ignoring the empty parameter. $match: { "school._id": "7011", "studentGradeLevels":

How to dynamically build mongodb query

允我心安 提交于 2020-01-02 16:07:25
问题 I have a match expression in a mongodb aggregation. There are 3 fields that are included in the match but they don't all always contain data. I only want to include the fields in the match if the field isn't empty. This is what the match looks like if all fields have data but for example, if the array used for studentGradeLevels is empty, then I don't want to include it or I want the query to still return data ignoring the empty parameter. $match: { "school._id": "7011", "studentGradeLevels":