gpt4 book ai didi

node.js和mongoose,如何批量插入?

转载 作者:太空宇宙 更新时间:2023-11-03 22:01:35 25 4
gpt4 key购买 nike

我正在调用 dropbox api“delta”来获取用户帐户中的所有图像文件。现在,我循环遍历条目数组,然后一一插入。我想知道是否有更好的插入方法。

    {
"has_more": false,
"cursor": "AAHmmLhWV0LhWya_OEKmZhPObxosWt4AHtk66EJiIm2_qoXPuwvyhWyuoH5Ybb_JVE9111PL06D_Td6v5bReJ3jpW_orbjBcYo4111LxRHqR3VKVxdQifemCZ7a-4njLA21TQbrIz5kaYe0vOczv668evAe",
"entries": [
[
"/four/220214_002.jpg",
{
"revision": 34,
"rev": "222005885b",
"thumb_exists": true,
"bytes": 105219,
"modified": "Sun, 23 Feb 2014 14:43:43 +0000",
"client_mtime": "Sun, 23 Feb 2014 14:43:42 +0000",
"path": "/four/220214_002.jpg",
"is_dir": false,
"icon": "page_white_picture",
"root": "dropbox",
"mime_type": "image/jpeg",
"size": "102.8 KB"
}
],
[
"/four/250214_002.jpg",
{
"revision": 65,
"rev": "412005885b",
"thumb_exists": true,
"bytes": 96909,
"modified": "Thu, 27 Feb 2014 00:45:28 +0000",
"client_mtime": "Thu, 27 Feb 2014 00:45:23 +0000",
"path": "/four/250214_002.jpg",
"is_dir": false,
"icon": "page_white_picture",
"root": "dropbox",
"mime_type": "image/jpeg",
"size": "94.6 KB"
}
],
...........

],
"reset": true
}

这是我的 dropboxEntry 模型。

            var mongoose = require('mongoose');

var dropboxEntrySchema = new mongoose.Schema({
//uid: Number,
dropbox_uid: Number,
revision: Number,
rev: String,
thumb_exists: Boolean,
bytes: Number,
modified: Date,
path: { type: String, unique: true},
path1: {type: String, unique: true},
is_dir: Boolean,
icon: String,
root: String,
size: String,
deleted: Boolean,
downloaded: Boolean,
thumbnail: String
});

module.exports = mongoose.model('DropboxEntry', dropboxEntrySchema);

最佳答案

从高层来看, Mongoose 似乎不支持这一点。(参见评论)。

因此,您可以通过以下方式访问 native 驱动程序的集合 API:YourModel.collection

然后您可以执行 native 插入命令:http://docs.mongodb.org/manual/reference/command/insert/#dbcmd.insert

它接受一组文档。

更新:

您可以使用mongodb bulk ops也来自 native 驱动程序 API。

关于node.js和mongoose,如何批量插入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22213166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com