问题标签 [mongolite]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
741 浏览

r - R- mongolite on OS X Sierra- 找不到合适的服务器

我正在尝试按照“ R 中的 MongoDB 入门”页面来启动和运行数据库。我的 PATH 中安装了 mongoDB,因此我可以mongod从终端运行并打开一个实例。虽然当我在后台打开一个实例并尝试在 R 中运行以下命令时:

在最后一条语句之后它会抛出一个错误:

如何启用它以找到我打开的连接?或者是别的什么?谢谢。

0 投票
0 回答
699 浏览

r - 如何使用 R mongolite 获取特定字段?

每条记录在我的收藏中都有很多字段,我只想获取其中的一小部分。中是否有解决方案mongolite

0 投票
0 回答
191 浏览

r - 在 Mac 上的 R 中使用 mongolite 执行 csv.file

我成功运行了基本查询,并且运行良好。

我得到以下结果

然后我尝试检索数据的某些部分,例如

我得到了以下结果

有谁知道为什么?提前非常感谢!!

0 投票
1 回答
195 浏览

json - 如何将字符串传递给进行 mongolite 查询的函数?

我必须进行很多mongoengine查询,所以我尝试编写一个函数来减少重复自己的频率。运行查询的基本代码是:

我的功能是:

但是当我尝试使用它时,它失败了。

为了了解发生了什么,我查看了我的函数实际传递给查询的内容:

我可以看到它不匹配。["它在字符串的两侧添加一个。但是,没有这个toJSON功能,我得到Error: Invalid JSON object: '{"field1": "foo", "field2": "bar"}'

有没有办法以这种方式将字符串传递给 JSON 对象,以便我可以编写一个接受字符串并返回mongolite查询结果的函数?

0 投票
2 回答
917 浏览

r - Mongolite and aggregation with $lookup on ObjectId vs character

Working with mongolite v0.9.1 (R) and MongoDB v3.4, I'd like to join two collections, the first one, the parent containing an ObjectId, the second one, the children containing the string value of the parents' ObjectId.

This is the basic syntax :

$lookup seems to take only field name, I've tried this, producing syntaxic errors :

So is there a way to deal with that ?

In the other way, I tried to save the parent's ObjectId in the children in ObjectId format with no luck (I still get a string in MongoDB) :

Is it possible to store an Id as ObjectId in mongolite?

Note : I'm doing bulk inserts so I can't deal with JSON string manipulations.

Any idea ?

Edit:

Here is an example of the collections i am using :

The Parent collection :

The Children collection :

0 投票
1 回答
342 浏览

r - 如何在R中优雅地为mongolite构建查询字符串?

我想编写一个函数来查询带有参数的 mongodb 数据库。

但是构建查询字符串很麻烦。

提前致谢。

0 投票
1 回答
985 浏览

r - 如何使用 R mongolite 更新子文档数组?

我正在使用 R mongolite 在具有以下结构的 mongo 集合中读写:

对于我收藏的给定文档,我想为每个站点添加一些属性。例如,我想像这样更新第一个文档:

在 mongolite 中,我能够将站点作为数据框获取并计算所需的属性:

但我找不到更新我的数据库的方法。我努力了:

不出所料,这给了我:

有没有办法通过将新属性添加到数组的现有元素来更新站点字段,或者我应该用一个替换整个站点字段$set?谢谢你的帮助。

我想我的问题与这个问题有关,所以我可能不得不遍历数组的每个元素......

0 投票
0 回答
205 浏览

r - 具有蒙古石的唯一索引

我看到我们可以通过简单地指定字段名称来添加索引:

我们如何指定唯一索引?IE:

0 投票
1 回答
360 浏览

r - 如何通过mongolite查询毫秒级的日期数据?

如下,'stime' 和 'etime' 的类型是 'Date' 毫秒:

我查询了这样的数据:

但是查询的数据是没有毫秒数据的UTC时间戳:

那么,如何查询毫秒级的数据呢?

0 投票
1 回答
835 浏览

r - 如何从 R 中的 Mongodb 中提取一列?

我有一个名为“consumerco”的 mongoDb,我需要从中提取一个名为“Company”的列作为表格进入我的 R 工作室。我怎么做 ?