当前位置: 首页 > 知识库问答 >
问题:

节点js中的mongoDB导出错误

萧心水
2023-03-14

我试图使用node连接mongodb。js。我偶然发现了一个问题。我正在得到要求(…)。pure不是函数错误。我试图使用这个网站上的确切代码“https://mongodb.github.io/node-mongodb-native/api-generated/collection.html“我的代码如下所示。

var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Binary = require('mongodb').Binary,
GridStore = require('mongodb').GridStore,
Grid = require('mongodb').Grid,
Code = require('mongodb').Code,
BSON = require('mongodb').pure().BSON,
assert = require('assert');

var uri = "mongodb://sa:psvitagamer5@cluster0-shard-00-00-
 tpfog.mongodb.net:27017,cluster0-shard-00-01-
  tpfog.mongodb.net:27017,cluster0-shard-00-02-
  tpfog.mongodb.net:27017/myNodeDb?ssl=true&replicaSet=Cluster0-shard-
  0&authSource=admin";


 MongoClient.connect(uri, function(err, db) {

   var collection = db.collection("userCollection");

    collection.insert({hello:'world_no_safe'});

   // Wait for a second before finishing up, to ensure we have written 
     the item to disk
   setTimeout(function() {

  // Fetch the document
   collection.findOne({hello:'world_no_safe'}, function(err, item) {
      assert.equal(null, err);
      assert.equal('world_no_safe', item.hello);
      db.close();
   })
   }, 100);
  //db.close();
});

请让我知道你的建议。

共有1个答案

郦翰学
2023-03-14
  1. 那个留档没有写好也没有测试,纯()mongodb-core模块

您应该安装mongodb core并使用:

BSON = require('mongodb-core').BSON;
 类似资料:
  • 问题内容: 以下代码使我在节点js中出现异常:“需要删除或更新” 由于我指定了更新操作,因此无法解决问题。 问题答案: 节点驱动程序中的语法与外壳程序中的语法不同,这是您使用的语法。 有一个单独的功能

  • 我有两个表有下面的模式,我想从用户表中获取用户名和密码,从信息表中获取全名。 var infoSchema=mongoose.Schema({khatam_id:String,user_id:String,fullname:String,}); var usersSchema=mongoose.Schema({user\u id:String,username:String,password:St

  • 我已经开始在一个简单的node.js应用程序中使用Q Promise包。所以我对如何在所有Promise序列完成后关闭数据库连接感兴趣。 例子: 我想在显示集合名称后关闭连接,但此匿名函数中没有db上下文。 有没有办法用promise模式处理此类案件?

  • 这是我的模型。 这是我的控制器用户。js: app.post('/Signup/',函数(req, res){{console.log(req.body.username); User.new用户( 这个概念是一旦用户名/密码被接受,一个API密钥将与用户名一起存储。虽然,用户名负载正在被接受,但是当我执行UserApiSchema调用来生成api时,没有生成这样的api。也没有错误。

  • 我是mongodb新手,所以需要一些帮助,用NodeJs导出和导入mongodb数据。我有一个mongodb数据库和一些集合(如产品集合、公式集合和规则集合,其中有产品id引用),我想根据api请求的参数导出不同集合中的数据,并生成包含相应数据的文件,该文件将在客户端浏览器上下载。用户可以使用导出的文件将导出的数据导入到另一个数据库实例中。我已经搜索了这个主题,并得到了这个答案,我不确定是否可以使

  • 我的自定义模块具有以下代码: 如果在我的模块外调用函数,效果很好,但是如果在模块内调用,则在运行时出现错误: (节点: 24372)UnhandledPromiseRejse警告:未处理的promise拒绝(拒绝id: 1):引用错误:未定义PrintNearestStore 当我将语法更改为: 它开始在模块内正常工作,但在模块外失败-我得到了错误: (节点: 32422)UnhandledPro