如何在MongoDB中加载初始数据? [英] How to load initial data in MongoDB?

查看:32
本文介绍了如何在MongoDB中加载初始数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何用初始数据填充mongodb吗?例如,对于传统的SQL数据库,您可以将所有SQL语句放在一个文本文件中,然后使用SQL命令来加载它.这对于单元测试非常有用.

Does anyone know how to populate mongodb with initial data? For example, with a traditional SQL database, you can put all your SQL statements in a textfile, then load that using a SQL command. This is extremely useful for unit testing.

使用mongo shell可以做到这一点吗?例如,将一列shell语句写到一个文件中,并获得mongo shell来读取文件并执行这些语句.

Is it possible to do this with the mongo shell? For example, write down a list of shell statements into a file, and get the mongo shell to read the file and execute the statements.

推荐答案

./mongo server:27017/dbname --quiet my_commands.js

在my_commands.js中:

In my_commands.js:

db.users.insert({name:"john", email:"john@doe.com", age:12});

这篇关于如何在MongoDB中加载初始数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆