1

In mongo I want to convert for docs in a collection:

{   
 "timestamp" : 1494624438268.0
}

to

{    
"timestamp" : NumberLong(1494624438268)
}

How can I do that?

jhhoff02
  • 1,179
  • 1
  • 17
  • 24
  • Don't know what exactly you are looking for ...Here's a link for ur help : https://docs.mongodb.com/manual/core/shell-types/#numberlong... – Nikhil May 23 '17 at 17:16

2 Answers2

2

i found it

db.getCollection('collection-name').find().limit(10).forEach(function(data) {
if (data.timestamp instanceof NumberLong === false) {
    data.timestamp=NumberLong(data.timestamp);});
0

You need to select your document and then update with the corresponding type.

db.collection.updateOne( { timestamp: 1494624438268.0 }, { $set:  { timestamp: NumberLong("1494624438268") } } )
Sercan Ozdemir
  • 4,641
  • 3
  • 34
  • 64