mongodb-scala

How do I get a Date to store as a Date in MongoDB instead of an Int64?

孤者浪人 提交于 2019-12-11 12:37:07
问题 I'm using the new MongoDB Scala Driver. When I store a java.util.Date, it is being stored in MongoDB as an Int64 instead of a MongoDB Date. I have some code that looks like this: implicit val writer = new Writes[Forecast] { def writes(x: Forecast): JsValue = { Json.obj( // ... "issueDateTime" -> x.issueDateTime // which is a java.util.Date // ... ) } } but what ends up in MongoDB is an Int64, not a Date. How do I get a Date into MongoDB? 回答1: If you are using the latest MongoDB Scala Driver

mongo update query given error

柔情痞子 提交于 2019-11-28 12:13:17
Coll.update(condition, new BasicDBObject("$set", data), true, true)) This is my update query in mongodb for some records it gives result as { "err" : null , "updatedExisting" : true , "n" : 1 , "ok" : 1.0} and at that time stored update query execute properly. but for some records it give result as { "err" : "not okForStorage" , "code" : 12527 , "n" : 0 , "ok" : 1.0} records neither update nor stoare in db in data there are multiple BasicDBList (list) used. if some one knows plz reply Thanks Ryan More than likely there are invalid characters in your document fields/keys. For example, you can't

mongo update query given error

你。 提交于 2019-11-27 06:57:57
问题 Coll.update(condition, new BasicDBObject("$set", data), true, true)) This is my update query in mongodb for some records it gives result as { "err" : null , "updatedExisting" : true , "n" : 1 , "ok" : 1.0} and at that time stored update query execute properly. but for some records it give result as { "err" : "not okForStorage" , "code" : 12527 , "n" : 0 , "ok" : 1.0} records neither update nor stoare in db in data there are multiple BasicDBList (list) used. if some one knows plz reply Thanks

mongodb get distinct records

假装没事ソ 提交于 2019-11-27 01:34:43
I am using mongoDB in which I have collection of following format. {"id" : 1 , name : x ttm : 23 , val : 5 } {"id" : 1 , name : x ttm : 34 , val : 1 } {"id" : 1 , name : x ttm : 24 , val : 2 } {"id" : 2 , name : x ttm : 56 , val : 3 } {"id" : 2 , name : x ttm : 76 , val : 3 } {"id" : 3 , name : x ttm : 54 , val : 7 } On that collection I have queried to get records in descending order like this: db.foo.find({"id" : {"$in" : [1,2,3]}}).sort(ttm : -1).limit(3) But it gives two records of same id = 1 and I want records such that it gives 1 record per id . Is it possible in mongodb? There is a

mongodb get distinct records

杀马特。学长 韩版系。学妹 提交于 2019-11-26 09:42:15
问题 I am using mongoDB in which I have collection of following format. {\"id\" : 1 , name : x ttm : 23 , val : 5 } {\"id\" : 1 , name : x ttm : 34 , val : 1 } {\"id\" : 1 , name : x ttm : 24 , val : 2 } {\"id\" : 2 , name : x ttm : 56 , val : 3 } {\"id\" : 2 , name : x ttm : 76 , val : 3 } {\"id\" : 3 , name : x ttm : 54 , val : 7 } On that collection I have queried to get records in descending order like this: db.foo.find({\"id\" : {\"$in\" : [1,2,3]}}).sort(ttm : -1).limit(3) But it gives two