[链接] Opening New Connections new Mongo() new Mongo() new Mongo() conn = new Mongo(); db = conn.getDB('myDatabase'); db = connect('localhost:27020/myDatabase'); ..

Write Scripts for the mongo Shell

参考链接

Opening New Connections

new Mongo()
new Mongo(<host>)
new Mongo(<host:port>)

conn = new Mongo();
db = conn.getDB("myDatabase");

db = connect("localhost:27020/myDatabase");

EXAMPLE

To print all items in a result cursor in mongo shell scripts, use the following idiom:

cursor = db.collection.find();
while ( cursor.hasNext() ) {
   printjson( cursor.next() );
}

Execute a JavaScript file

mongo localhost:27017/test myjsfile.js

load("myjstest.js")

To print all items in a result cursor in mongo shell scripts, use the following idiom:

cursor = db.collection.find();
while ( cursor.hasNext() ) {
   printjson( cursor.next() );
}

Execute a JavaScript file

mongo localhost:27017/test myjsfile.js

load("myjstest.js")

The load() method accepts relative and absolute paths. If the current working directory of the mongo shell is /data/db, and the myjstest.js resides in the /data/db/scripts directory, then the following calls within the mongo shell would be equivalent:

load("scripts/myjstest.js")
load("/data/db/scripts/myjstest.js")
  • MongoDB

    MongoDB(来自于英文单词“Humongous”,中文含义为“庞大”)是一个基于分布式文件存储的数据库,由 C++ 语言编写。旨在为应用提供可扩展的高性能数据存储解决方案。MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。它支持的数据结构非常松散,是类似 JSON 的 BSON 格式,因此可以存储比较复杂的数据类型。

    59 引用 • 46 回帖
回帖
请输入回帖内容...