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

查看:9
本文介绍了如何在 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天全站免登陆