Tag: mongo

帆 – 蒙哥:多对多的关系是不适用于我的应用程序。 接下来的文档还是给它空的数组

我用mongodb使用js风帆。 这里是我的EventTags模型: EventTags.js module.exports = { schema: true, attributes: { eventList: { collection: 'Events', via:'tagList' }, event_tag_name:{ type:'string', required:true, unique:true } } }; 这里是我的事件模型: Events.js module.exports = { schema: true, attributes: { tagList: { collection: 'EventTags', via:'eventList' }, title:{ type:'string',required: true}, blurb:{ type:'string'}, description:{ type:'string'}, venue: {type: 'string',required: true}, } }; 创build了EventTags,这是我的JSON响应。 { "status": 109, […]

在sailjs 500内部服务器错误

我是sailsjs中的新手,并试着按照教程学习,我在插入post的时候出现了500内部错误。 这是我的所有文件: //DashboardController.js newpost: function(req, res){ var params = req.params.all(); var userId = req.session.user_detail._id; //return false; Post.create({ title: params.heading, description: params.message, posted_by: params.userId }).done(function(error, post_created){ if(err){ }else{ req.session.post_details = post_created; res.redirect('/dashboard'); } }); } // Dashboard.js模型 module.exports = { attributes: { title:{ type:'string', required:true, columnName:'title' }, description: { type:'text', columnName:'description' }, posted_by: { type: 'integer', […]

在sails更新查询中得到问题

我是新的帆JS,并得到一些问题,我的更新查询显示更新成功,但它并没有更新MongoDB收集logging。 我不在哪里做愚蠢的错误。 这是控制器function edit: function(req, res){ var uid = req.params.id; console.log("Request body———-" +uid); console.log(req.body.heading); console.log(req.body.message); Dashboard.update( { _id : uid }, {title : "req.body.heading" , description : "req.body.message" }).exec(function(err, doc){ if(err){ console.log("Error while update"+err); }else{ console.log("Successfuly Updated"); res.redirect('dashboard/index'); } }); } 这是模型文件: module.exports = { attributes: { title:{ type:'string', //required:true, columnName:'title' }, description: { type:'text', […]

Sails.js:嵌套的MongoDB查询

我正在使用Sails v0.11,并且正在开发一个独立的导入脚本,以便将数据导入到mongoDB中 – 现在是非工作部分 – build立模型之间的关联。 对于这个过程,我在模型中引入了临时助手属性,以便查找关联的logging,并用真实的MongoDB _idsreplace它们。 该脚本启动Sails以便能够使用其function(水线等): var app = Sails(); app.load({ hooks: { grunt: false }, log: { level: 'warn' } }, function sailsReady(err){ processUsers()查找所有用户及其_ids并遍历它们以调用第二个函数addOrgsToOneUser() var processUsers = function() { // Iterate through all users in order to retrieve their _ids and app.models['user'].native(function(err, collection) { collection.find({}, projectionOrgInUser).toArray(function (err, users) { Async.eachSeries(users, function […]

nodejs mongodb连接/断开模式

我用mongodb为后端使用sails.js。 而且我听说为每个请求连接到数据库可能非常昂贵,这就是为什么其他非单线程编程语言为数据库持有连接池的原因? 所以我想知道 Nodejs是否利用数据库连接池?(我想我已经有一个答案是否定的,只是为了确保) 既然我用mongodb驱动程序使用sails-mongo,那么每当我对mongodb做一些指示时,是否会build立与mongodb的新连接? 或者它只是保持一个连接,并每次重复使用它? 假设sails-mongo每次连接到mongodb然后断开连接,那么如果连接不能build立呢? 会干扰节点线程,因此以后所有请求都无法处理? 我很担心…

在风帆js联合search

我有游戏集合: { "name": "Play RoadRash", "version": "1.0.0", "icon": "image-md-two-thirds.png", "id": "6dc41c3fa0e7" } 和平台集合: { "name": "PlayStation", "version": "7", "icon": "playstation.jpg", "id": "55eaf322f1a16" } 我正在尝试创build一个search查询谁search这两个集合中的名称参数。 有没有人有任何想法如何search在航行水线多个集合?

SailsJS geoNear Issues

在SailsJS中使用geoNear工作时遇到了很多麻烦。 在我的UserController.js我想在我的用户模型中的location字段上做一个geoNear查询。 它被定义为带有2d索引的JSON。 以下是该领域数据的一个例子: "location" : { "type" : "Point" , "coordinates" : [ 42.8003 , -73.8808 ]} 在我的UserController中,我的geoSearch方法如下所示: geoSearch: function(req, res) { //sails.log.verbose(req); var lat = req.param('lat'); var lng = req.param('long'); var limit = req.param('limit') || 50; var maxDistance = req.param('radius') || 5000; //meters sails.log.verbose('lat : ' + lat); sails.log.verbose('lng : ' + lng); […]

SailsJS:如果它有未声明的属性,则阻止Model.create()

如果包含未在api / models / YourModel中声明的属性,是否有阻止实体创build的方法? 例如,假设我使用了MongoDB,并且有这个User模型: module.exports = { attributes: { name:{type:'string'}, age:{type:'number'} } }; 我试图用这个代码创build: User.create({name:'Walter Jr',age:8,missingTest:'something'}).exec(function createCB(err,created){ console.log('should fail'); }); 另外,如果一个关系/关联到另一个模型,不应该创build失败,如果实体ID指向一个无效的实体? 也许我在validation过程中遗漏了一些东西,但到目前为止,这种行为对我来说似乎有点奇怪,如果水线有复合主键支持,那也不错。

在集合/对象中查找 – SailsJS和Waterline ORM

我使用SailsJS,所以Waterline ORM和MongoDB。 我将多个用户ID保存在一个名为Labels的集合中的一个对象中(这样一个标签可以属于多个用户)。 我在Mongo中有一个数据结构,像这样: labels: { id: … belongs_to: { **id of user**: 2 (I'm using this is for individual user ordering) } } 如果我目前是ID为101的用户 – 我想查找()label.belongs_to中存在101的所有标签条目。 我search了文档,但无法find如何做到这一点。 我试过(没有运气)类似于: Label.find().where({ belongs_to: {'contains' : user_id}) 这是解决这个问题的最好方法吗?如果是的话,我怎样才能通过Sails实现呢?

如何使Sails模型指向不同的数据库?

我创build了一个Sails应用程序,我需要对模型数据库进行事务处理的面板pipe理。 关键是,后端架构和数据pipe理需要Sails应用程序中相同模型的不同数据库。 所以,我的模型看起来像这样: module.exports = { connection: 'seasonDB', autoPK: false, attributes: { id: { type: 'string', primaryKey: true, required: true }, avatar: { type: 'string', defaultsTo: '' }, price: { type: 'integer', defaultsTo: function () { var prices = [ 7000000, 5000000, 4000000, 2500000, 1000000 ]; return prices[_.random(prices.length -1)]; } }, description: { type: 'string', […]