如何在 MongoDB 中插入 LONG 类型的数字?

mongodbdatabasebig data analytics

要插入 LONG 类型的数字,请使用 NumberLong() 函数。它用于处理 64 位整数。让我们创建一个包含文档的集合。

> db.demo273.insert({
...   Name:"Robert",
...   id: NumberLong("100000000000001"),
...   isActive:true
...})
WriteResult({ "nInserted" : 1 })
> db.demo273.insert({
...   Name:"David",
...   id: NumberLong("98888888888888888"),
...   isActive:false
...})
WriteResult({ "nInserted" : 1 })
> db.demo273.insert({
...   Name:"Mike",
...   id: NumberLong("999999999999"),
...   isActive:true
...})
WriteResult({ "nInserted" : 1 })

借助 find() 方法显示集合中的所有文档 −

> db.demo273.find();

输出

这将产生以下输出 −

{ "_id" : ObjectId("5e4824df1627c0c63e7dbac3"), "Name" : "Robert", "id" : NumberLong("100000000000001"), "isActive" : true }
{ "_id" : ObjectId("5e4824e01627c0c63e7dbac4"), "Name" : "David", "id" : NumberLong("98888888888888888"), "isActive" : false }
{ "_id" : ObjectId("5e4824e11627c0c63e7dbac5"), "Name" : "Mike", "id" : NumberLong("999999999999"), "isActive" : true }

相关文章