mongodb-query

subtraction in mongo query does not work?

耗尽温柔 提交于 2019-12-23 02:28:48
问题 I have a collection as follow: { "_id" : ObjectId("5491d65bf315c2726a19ffe0"), "tweetID" : NumberLong(535063274220687360), "tweetText" : "19 RT Toronto @SunNewsNetwork: WATCH: When it comes to taxes, regulations, and economic freedom, is Canada more \"American\" than America? http://t.co/D?", "retweetCount" : 1, "source" : "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>", "Date" : ISODate("2014-11-19T04:00:00.000Z"), "Added" : ISODate("2014-11-19T04:00:00.000Z"),

Update array in mongo and upsert

不想你离开。 提交于 2019-12-23 02:18:10
问题 I'm trying to update an array within a document and it works correctly, but when I want to add a new element with upsert fails how to run an error. I've been searching on google for a few hours and the mongodb documentation and what I have tried I cannot operate. The structure of the collection is: { "name" : String, "providerId": Number, "description": String, "providers": [ { "merchantId": String, "name": String, "valid": Boolean, "data": String }, { "merchantId": String, "name": String,

Update array in mongo and upsert

余生颓废 提交于 2019-12-23 02:18:07
问题 I'm trying to update an array within a document and it works correctly, but when I want to add a new element with upsert fails how to run an error. I've been searching on google for a few hours and the mongodb documentation and what I have tried I cannot operate. The structure of the collection is: { "name" : String, "providerId": Number, "description": String, "providers": [ { "merchantId": String, "name": String, "valid": Boolean, "data": String }, { "merchantId": String, "name": String,

MongoDb aggregation query with $group and $push into subdocument

岁酱吖の 提交于 2019-12-23 01:34:16
问题 I have a question regarding the $group argument of MongoDb aggregations. My data structure looks as follows: My "Event" collection contains this single document: { "_id": ObjectId("mongodbobjectid..."), "name": "Some Event", "attendeeContainer": { "min": 0, "max": 10, "attendees": [ { "type": 1, "status": 2, "contact": ObjectId("mongodbobjectidHEX1") }, { "type": 7, "status": 4, "contact": ObjectId("mongodbobjectidHEX2") } ] } } My "Contact" collection contains these documents: { "_id":

Mongoose - Search for text in three fields based on score or weightage

非 Y 不嫁゛ 提交于 2019-12-22 23:39:17
问题 I am using Mongoose on top of MongoDB. This is how my model looks. var BookSchema = new Schema({ name: String, viewCount: { type: Number, default: 0 }, description: { type: String, default: 'No description' }, body: { type: String, default: '' } } }); I need to search for some text on over Name, Description, Body fields. So far this is what I am doing & its working: Book.find().or([{ 'name': { $regex: term, $options: "$i" }}, { 'description': { $regex: term, $options: "$i" }}, { 'body': {

Iterating through PyMongo cursor throws InvalidBSON: year is out of range

只谈情不闲聊 提交于 2019-12-22 20:35:01
问题 I am using PyMongo to simply iterate over a Mongo collection, but I'm struggling with handling large Mongodb date objects. For example, if I have some data in a collection that looks like this: "bad_data" : [ { "id" : "id01", "label" : "bad_data", "value" : "exist", "type" : "String", "lastModified" : ISODate("2018-06-01T10:04:35.000Z"), "expires" : Date(9223372036854775000) } ] I will do something like: from pymongo import MongoClient, database, cursor, collection client = MongoClient(

Iterating through PyMongo cursor throws InvalidBSON: year is out of range

给你一囗甜甜゛ 提交于 2019-12-22 20:34:42
问题 I am using PyMongo to simply iterate over a Mongo collection, but I'm struggling with handling large Mongodb date objects. For example, if I have some data in a collection that looks like this: "bad_data" : [ { "id" : "id01", "label" : "bad_data", "value" : "exist", "type" : "String", "lastModified" : ISODate("2018-06-01T10:04:35.000Z"), "expires" : Date(9223372036854775000) } ] I will do something like: from pymongo import MongoClient, database, cursor, collection client = MongoClient(

find first of documents for each distinct values for one field

强颜欢笑 提交于 2019-12-22 14:58:37
问题 With a collection of documents with fields field1 , field2 , field3 and so on, I need to find distinct values for field3 for each distinct value of field3 , need to get the first document with each distinct value in field3 For # 1, I could do db.myCollection.distinct("field3") How do I go about #2 ? Sample Collection: [ { "field1": 11, "field2": "toyota", "field3": "camry" }, { "field1": 22, "field2": "toyota", "field3": "corolla" }, { "field1": 33, "field2": "toyota", "field3": "camry" }, {

MongoDB: Update a field of an item in array with matching another field of that item

我们两清 提交于 2019-12-22 11:23:54
问题 I have a data structure like this: We have some centers . A center has some switches . A switch has some ports . { "_id" : ObjectId("561ad881755a021904c00fb5"), "Name" : "center1", "Switches" : [ { "Ports" : [ { "PortNumber" : 2, "Status" : "Empty" }, { "PortNumber" : 5, "Status" : "Used" }, { "PortNumber" : 7, "Status" : "Used" } ] } ] } All I want is to write an Update query to change the Status of the port that it's PortNumber is 5 to "Empty". I can update it when I know the array index of

arrayFilters in mongodb

青春壹個敷衍的年華 提交于 2019-12-22 11:16:04
问题 I have the following schema. { posts: [ { _id: '5ayuunbdsyuuuyut778' replies: [{ _id: "67hfudj7e9whduu888", text: "something" }] } ] } I want to update the text in particular reply. I am using mongoose. I have written the query as follows Post.findOneAndUpdate( {'posts.replies._id': _id}, {$set: {'posts.$[post].replies.$[reply].text': "something1"}}, { arrayFilters: [{'post._id': postId}, { 'reply._id': _id }]} ) This query is not updating the document. Am I missing something? Do I need to