Tag: mongodb

在mongodb中显示字段值部分匹配的文档

以下是我的电影架构: "_id" : ObjectId("59b9501600fcb397d6acd5bb"), "theatreid" : 2, "name" : "carnival cinemas", "location" : "kanjulmarg", "address" : "sec 2,kanjul, Mumbai, Maharashtra 400703", "shows" : [ { "mname" : "bareily ki barfi", "timings" : [ 10, 13, 14, 16, 22 ] }, { "mname" : "Toilet:ek prem katha", "timings" : [ 8, 9, 14, 16, 20, 23 […]

.aggregate()2藏品mongoose

这是第一个模式: const ProSchema = new Schema({ _id: { type: Schema.Types.ObjectId }, Cv: {Fonction: {Pro: {type: Boolean,}, Secretaire: {type: Boolean} } }) 这是第二个Schema: const CabSchema = new Schema({ Pro: [{ type: Schema.Types.ObjectId, ref: 'ProSchema' }], InfoCab: { Nom: {type: String} }); 创build一个内阁: var cabinet = new cabModel({ _id: new mongoose.Types.ObjectId(), InfoCab:{Nom: "Clinique Toto"} //This is the […]

mongoose全文检索不起作用

我正在尝试search一个使用文本作为参数的对象。 我在我的mongodb中有以下数据: [ { "_id": "59d518859eacefa4555d6edb", "id": "A07", "nome": "Outras doenças intestinais por protozoários" }, { "_id": "59d518859eacefa4555d6edc", "id": "A08", "nome": "Infecções intestinais virais, outras e as não especificadas" } ] 我的模特: var cid = new Schema({ id: String, nome: String }, {collection: 'cid'}); cid.index({'id': 'text', 'nome': 'text'}); search方法: var cid = require('./cid.model'); cid.find({$text: {$search: […]

使用ActiveAdmin迁移Rails应用程序到NodeJS

我正在将Ruby on Rails中的另一个开发人员创build的应用程序迁移到NodeJS,该应用程序有一个ActiveAdmin来处理一些操作并检查一些统计信息,我想知道可以在Node中使用什么类似的工具/框架来迁移尽可能减less痛苦。 另外,除了这个问题之外,我想问一下关于使用Node PostgreSQL实现和迁移到Mongo的问题(我知道没有看到代码不容易回答,但是我正在寻找见解,例如:Postgres在Node中没有太多贡献者,更好的移民到Mongo) 提前致谢!

为mongoosevalidation设置错误代码

我正在使用mongoosevalidation来validation我的模型。 例如: var some_schema = new Schema({ title: { type : [String, 'title must be string'], required: [true, 'title is required'] } }) 此架构具有自定义错误消息,我也想设置自定义错误代码

geoNear没有返回任何结果,尽pipe项目在范围内(mongoose)

所以这里是我的模型: const mongoose = require('mongoose'); const Schema = mongoose.Schema; // create geolocation Schema const GeoSchema = new Schema({ type: { type: String, default: "point" }, coordinates: { type: [Number], index: "2dsphere" } }); // create ninja Schema & model const NinjaSchema = new Schema({ name: { type: String, required: [true, 'Name field is required'] }, […]

NodeJS MongoDB游标toArraycallback函数不会对父范围variables进行更改

MongoClient.connect(dburl, function (err, db) { var collections = []; db.listCollections().toArray(function (err, collInfos) { for (var i = 0; i < collInfos.length; i++) { collections[i] = collInfos[i].name; } console.log(collections); }); console.log(collections); }); 所以我想把我所有的数据库集合放到一个string数组中,这是我的一部分代码。 问题是, toArraycallback之外的console.log首先被执行并输出[] ,而toArraycallback中的console.log正确地输出数组。 在我看来,有一些范围问题,但我不熟悉NodeJS和MongoDB究竟如何。

MongoDB + NodeJS提供16个字符的唯一ID

我正在寻找一种有效的方式来创build长度为16个字符的64位UUID。 每个ID都必须是随机的,所以你不能预测其他的ID。 另外我不确定如何检查碰撞是否发生,我怎样才能以有效的方式寻找它们。 我正在使用一个mongoDB和一个服务器节点JS。 一个例子:我调用函数来创build1.000.000个密钥,并且在数据库中已经保存了数百万个密钥。 我怎样才能保证每个密钥都存在只有那些没有比较每个密钥到数据库中现有的密钥? 我希望有人能帮助我。 谢谢 :)

在使用node.js和mongodb的聊天应用程序中,消息正在为每个页面刷新保存。 热解决?

这里是我的js代码,用于检索已经存在的用户数据,现在我正在检索相同的聊天logging,并在我的内部聊天窗口 这里是我的代码写在index.js文件 io.on('connection', function(socket){ var query = Chat.find({}); query.sort('-created').limit(4).exec( function(err,data){ if (err) { res.send(err); } else{ io.sockets.emit("chat history", data); } }); }); 我正在发送聊天logging,同样在chat.js文件中显示如下 socket.on("chat history", function(data){ for(var i=data.length-1; i >=0; i–){ displaymsgs(data[i]); } }); function displaymsgs(data){ feedback.innerHTML = ""; output.innerHTML += '<p><strong>' + data.username + ':</strong>' + data.message + '</p>'; } 现在我无法获得限制的消息(4),并且每当页面重新加载时,消息也正在加载到数据库。 请给我一个解决scheme,我犯了错误,如何接近它。 先谢谢你。

mongoose不返回所有的领域

所以我有: UserSchema : var UserSchema = new mongoose.Schema({ firstName: String, lastName: String, image: { type: String, default: "http://via.placeholder.com/250×200" }, email: { type: String, required: [true, "Email missing."], unique: true }, kind: { type: String, enum: ["Admin", "Teacher", "Student"], default: "Student" }, isAdmin: { type: Boolean, default: false }, isPromote: { type: Boolean, default: false }, […]