语法错误:在将MongoDB查询输出到文本文件时,语句前缺少missingl [英] Syntax error: missingl before statement while outputting MongoDB query to a text file
问题描述
我到MongoDB的年龄为1天,所以请多多包涵.我只是想将一个简单的查询输出到* .json文件.查询是:
I am 1 day old to MongoDB so bear with me. I am simply trying to output a simple query to a *.json file. The query is:
db.collection.findOne()
//集合用正确的集合名称替换,该查询以"use db"命令为前提,其中db替换为正确的数据库名称
然后,参考这篇文章以及其他一些答案,我将执行以下查询:
Then, in reference to this article and a bunch of other SO answers, I perform the following query:
--eval "printjson(db.results.findOne())" >> sample.json
我什至创建了一个空白的sample.json文件,并使用-eval等进行了--eval实验.我不断得到:
I even created a blank sample.json file, and I experimented --eval with -eval etc. I keep getting:
语法错误:缺少;语句(shell)之前:1
我在任意位置添加了半冒号,但是我不知道为什么这对我不起作用.
I add semi colons at arbitrary places, but I have no idea why this doesn't work for me.
有人可以指出我在这里想念的东西吗?
Can anybody point out what I am missing here?
完整的命令序列:
mongo
use dbname
--eval "printjson(db.collectionName.findOne())" >> sample.json
PS:命令db.collectionName.findOne()确实给了我输出
P.S: The command db.collectionName.findOne() does give me an output
推荐答案
-eval应该作为参数传递给"mongo"命令.我在下面尝试过,并且有效:
--eval should be passed as an argument to "mongo" command. I tried below and it worked:
C:\>mongo localhost:27017/dbname --eval "printjson(db.results.findOne())" >> sample.json
这篇关于语法错误:在将MongoDB查询输出到文本文件时,语句前缺少missingl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!