mongodb-query

mongodb update matched doc fail

﹥>﹥吖頭↗ 提交于 2019-12-13 05:15:29
问题 There are 10000 docs import by mongoimport, the _id is 6 length random string {_id:"xxxxxx","u":0,"t":0} because mongoimport can not specifiy data type, so string like "123456" was imported as type int. So I manually delete originals and re-insert them as db.xxx.insert({_id:"123456","u":0,"t":0}) Because the default type of 0 is Double, so I change them to int by: db.xxx.update({},{$set:{u:NumberInt(0)}},false,true) WriteResult({ "nMatched" : 100000, "nUpserted" : 0, "nModified" : 99994 })

how to find document with mongoDB using mongodb java in sub array of document?

廉价感情. 提交于 2019-12-13 04:49:32
问题 This is really hard. I want to find the select nodes.index where radio.mac_address="00:06:5A:03:2E:5B" . how can I get this query in MongoDB using java? My mongodb is as following. I tried so many queries. one of them is as following BasicDBObject query = new BasicDBObject("nodes.radios.mac_address", "mac_address value"; BasicDBObject fields = new BasicDBObject("nodes.$", 1); DBCursor cursor = node_info.find(query, fields); Updated First on got solved How can i also write update query like

mongoid - mongodb, mapreduce get scope varriable or pass it to output

半世苍凉 提交于 2019-12-13 04:46:07
问题 In mapreduce I have a scope total_count to calculate something after grouping something. How can I get back the that scope varriable in output? EDIT: map = %Q{ function() { ttotal_commission += this.commission; tuniq_commission += this.commission; // add first if it not goto reduce emit({ip: this.ip, campaign_id: this.campaign_id}, {commission: this.commission, abc: this.commission}); } } reduce = %Q{ function(key, values) { tuniq_commission += values[0].commission; // add 1 and substract

how to insert new data in an embedded document in MongoDB

亡梦爱人 提交于 2019-12-13 04:44:14
问题 I have a document about employees of a company and each employee has multiple addresses. It is an embedded document { _id: 12, emp_name: "Joy Pett", emp_gender: "Male", emp_address: [ { street: "123 Fake Street", city: "Faketon", state: "MA", }, { street: "1 Some Other Street", city: "Boston", state: "MA", } ] } Now I want to insert a new address for this employee. What is the query to insert new address for this employee?? 回答1: What is want is update your document. You need to use the update

Mongo DB remove old data using remove command

给你一囗甜甜゛ 提交于 2019-12-13 04:37:39
问题 My mongo db contains > db.collection.find(); { "_id" : ObjectId("55f8e493d97731874b1235bd"), "Date" : "14-12-2014", "Value" : 25.36 } { "_id" : ObjectId("55f8e497d97731874b1235be"), "Date" : "14-11-2014", "Value" : 25.36 } { "_id" : ObjectId("55f917f748f91b35cf1ddaac"), "Date" : "14-01-2015", "Value" : 25.36 } { "_id" : ObjectId("55f917fc48f91b35cf1ddaad"), "Date" : "14-02-2015", "Value" : 25.36 } { "_id" : ObjectId("55f9180148f91b35cf1ddaae"), "Date" : "14-03-2015", "Value" : 25.36 } { "_id"

compare multiple values inside aggregation and display result in array in mongodb

混江龙づ霸主 提交于 2019-12-13 04:20:12
问题 I have the following table :- id order_number product_number order_status schedule_datetime 1 001 001.1 SUCCESS 20180103 2 001 001.2 SUCCESS 20180102 3 111 111.1 SUCCESS 20171225 4 111 111.2 SUCCESS 20171224 5 222 222.1 INPROGRESS 20171122 6 222 222.2 ON_HOLD 20171121 7 222 222.3 PARTLY_SUCCESS 20171121 What i am trying here, if any of the product_number matches the status given in the query, it should display the year and list of order_numbers. Input 1: order_status = SUCCESS, below output

How to use $update/ $set operator in aggregation pipeline mongodb?

狂风中的少年 提交于 2019-12-13 04:16:00
问题 I am trying to update a field called name in my coll1 collection based on certain criteria. I first created a create an aggregation pipeline that filters out documents based on my criteria. var local_filter = { "$or" :[ {'fullText': {'$eq': "404 Error"}}, {'fullText': {'$eq': "Unknown Error"}}, {'fullText': {'$eq': "503 Error"}}, {'fullText': {'$eq': "400 Error"}}, {'fullText': {'$eq': "500 Error"}}, {'fullText': {'$eq': "Read timed out"}}, {'fullText': {'$eq': "410 Error"}}, {'fullText': {'

MongoDB: How do I query for the number of elements in an array of documents/dictionaries?

走远了吗. 提交于 2019-12-13 04:13:40
问题 I have a document that contains a list of dictionaries that show a user's login date and session id. How do I query for the number of total logins using MongoDB shell? { "uname": "johndoe", "loginActivity": [{}, {'date': '01/30/2018 15:52', 'SID': '02fe602a'}, {'date': '01/31/2018 20:32', 'SID': '2358eeea'}, {'date': '01/31/2018 20:06', 'SID': '3d720386'}, {'date': '01/25/2018 01:41', 'SID': '40b30ff2'}, {'date': '01/30/2018 15:55', 'SID': '4a3b9129'}, {'date': '01/31/2018 11:26', 'SID':

$geowithin:$polygon doesn't use 2dsphere index

风格不统一 提交于 2019-12-13 04:12:05
问题 I am having a collection of documents like following: { "_id" : ObjectId("5bc15f23d672e9086ca4fbac"), "Location" : { "GeoJson" : { "type" : "Point", "coordinates" : [14.4199254356, 50.0700249768] } } And I have Index created as following { Location.GeoJson2dsphere : "2dsphere" } And now to the problem when I use the $polygon for searching, i've got the results, but query is not using index, so it's slow. Here is the query .find({"Location.GeoJson" : { "$geoWithin" : { "$polygon" : [ [14

How to query nested objects?

怎甘沉沦 提交于 2019-12-13 03:58:02
问题 I have a problem when querying mongoDB with nested objects notation: db.messages.find( { headers : { From: "reservations@marriott.com" } } ).count() 0 db.messages.find( { 'headers.From': "reservations@marriott.com" } ).count() 5 I can't see what I am doing wrong. I am expecting nested object notation to return the same result as the dot notation query. Where am I wrong? 回答1: db.messages.find( { headers : { From: "reservations@marriott.com" } } ) This queries for documents where headers equals