草庐IT

IME_NULL

全部标签

javascript - MongoDB Node.js 类型错误 : Cannot read property 'db' of null

我正在为我的项目制作一个数据库,但是在这段代码中:functiongetallvideos(callback){MongoClient.connect(url,function(err,client){constdb=client.db("cathub")db.collection("videos",function(err,collection){collection.find().toArray(function(err,res){callback(res)})})db.close()})}我收到这个错误:TypeError:Cannotreadproperty'db'ofnull

MongoDB 平均返回 NULL

我正在使用MongoDB获取汽车发动机尺寸的平均值。但是,聚合Average函数一直返回NULL。部分DB如下:{"_id":1,"car":{"engineSize":1.5},"addresses":["X","A"]}{"_id":6,"car":{"engineSize":1.5},"addresses":["X"]}{"_id":2,"car":{"engineSize":1.3}}{"_id":5,"car":{"engineSize":1.4}}{"_id":3,"car":{"engineSize":1}}我用来检查平均值的命令是:db.project.aggregat

mongodb - Mongo - 将 null 或 undefined 字段视为特定值

我有以下情况:考虑一个包含以下文档的集合:[{'_id':ObjectId('somehting'),'date':null},{'_id':ObjectId('somehting'),},{'_id':ObjectId('somehting'),'date':'2015-01-0112:12:12'},manyothers]现在我有以下查询查找日期介于值之间的文档db.getCollection('validation_archive').find({'date':{$lte:'[date_here]',{$gte:'[date_here]'}}});一切正常,除了为空或不存在的字段

javascript - 无法读取 null 的属性 'password'

我正在使用mongodb和nodejs创建一个小数据库,我想更新一个字段但是我有这个错误,代码是,模型的名称是“ListaSalas”:router.post('/updatesala',function(peticion,responsep){varpassword=peticion.body.password;varurl=peticion.body.url;ListaSalas.findOne({'url':url},function(err,respuesta){varPassBusca=respuesta.password;if(PassBusca){responsep.wr

node.js - 在 MongoDB 中按 id 查找返回 null

我是NodeJS和MongoDB的新手我正在尝试做一些非常基本的事情,但它似乎不起作用。我确信我在某处遗漏了一些东西。基本上,我试图根据ID从数据库中查找用户。这是我的代码:functionfindUser(id,cb){MongoClient.connect(cs,function(err,db){varcol=db.collection('users');col.findOne({_id:id},function(err,user){//Valueofuserhereisalwaysnull//However,ifImanuallycheckthedatabase,//Icancl

c# 和 mongoDB - 无法从 BsonType Null 反序列化

我是MongoDB的新手,我一直在认真阅读使用MongoDB2.2和官方C#驱动程序的初学者指南http://www.codeproject.com/Articles/524602/Beginners-guide-to-using-MongoDB-and-the-offic一切似乎都很顺利,除了我不确定如何处理MongoDB空值这是我的数据结构publicclassDataStructure{publicObjectId_id{get;set;}publicDateTimeCreatedOn{get;set;}publicDateTimeUpdatedOn{get;set;}publi

node.js - mongoDB 查询返回 null,但使用 .toArray 返回数据

我在mongoDB中有这个查询varquery={"_id":newObjectID(id)};varitems={items:1};warehouses.find(query,items,function(error,docs){if(error){error(error);return;}success(docs);});我想通过_id从文档中获取项目。这返回我docs.items=undefined但是当我这样做的时候:warehouses.find(query,items).toArray(function(error,docs){if(error){error(error);

node.js - Mongoose findOne 数组的 ObjectId 返回 null

在使用ObjectId数组执行findOne查询时遇到一些问题。简化架构如下:型号:varInboxSchema=newSchema({_users:[{type:mongoose.Schema.ObjectId,ref:'User',required:'Usersarerequired',unique:true}]}mongoose.model('Inbox',InboxSchema)查询:varusers=[];varuserIds=['5567ead844997f969fe3f00f','558b8492f1723b090b414765'];for(vari=0;i尽管Inbox

node.js - 无法使用 Node/Express/Mongodb 读取 null 的属性 'find'

我正在按照教程创建一个简单的Node/Express/MongooseRESTAPI。我在一个终端上运行mongod,在另一个终端上运行我的Node应用程序。我的应用://BASECONFIG//=========================================================varexpress=require('express'),bodyParser=require('body-parser'),util=require('util'),app=express(),port=process.env.PORT||8000,//databasedbUR

javascript - 如何从 graphql 突变而不是 null 返回新记录

我通读了apollo-server-tutorial,我试图只用mongodb复制它——没有sqllite。我来自meteor,所以我正在学习async和mongoose。我对addAuthor()的修改工作正常(我在数据库中看到一条新记录)但graphiql返回null。我如何让它返回预期的字段?mutation{addAuthor(firstName:"falieson",lastName:"p"){_idfirstNamelastName}}{"data":{"addAuthor":null}}架构:https://github.com/Falieson/apollo-serve