我有Category
模特:
Category:
...
articles: [{type:ObjectId, ref:'Article'}]
Run Code Online (Sandbox Code Playgroud)
文章模型包含ref Account model
.
Article:
...
account: {type:ObjectId, ref:'Account'}
Run Code Online (Sandbox Code Playgroud)
因此,填充的articles
Category模型将是:
{ //category
articles: //this field is populated
[ { account: 52386c14fbb3e9ef28000001, // I want this field to be populated
date: Fri Sep 20 2013 00:00:00 GMT+0400 (MSK),
title: 'Article 1' } ],
title: 'Category 1' }
Run Code Online (Sandbox Code Playgroud)
问题是:如何填充填充字段的子字段(帐户)([articles])?我现在就是这样做的:
globals.models.Category
.find
issue : req.params.id
null
sort:
order: 1
.populate("articles") # this populates only article field, article.account is not populated
.exec (err, categories) …
Run Code Online (Sandbox Code Playgroud) 我的网站每个页面都有一个注册表.注册期间可能会出现一些错误.捕获错误后,我必须将用户返回到上一页,显示一些错误消息.问题是我不知道用户从哪个页面进行了注册,所以我使用了res.redirect('back');
.但是,我不能只是重定向用户,我也要显示错误信息,所以我必须传递一些参数.但res.redirect('back', (reg_error:'username')})
不能直接使用,因为res.redirect()
不支持参数.如何使用某个参数渲染上一页?
这不是一个具体的应用程序/代码问题,它只是常见的应用程序架构.
我正在尝试理解组织我的猫鼬应用程序的正确方法.因为我是猫鼬的新手,我现在就是这样做的:
核心/ settings.js
var mongoose = require('mongoose');
exports.mongoose = mongoose;
mongoose.connect('mongodb://localhost/blog');
exports.db = mongoose.connection;
Run Code Online (Sandbox Code Playgroud)
核心/ models.js
settings = require("./settings");
// post schema
var postSchema = settings.mongoose.Schema({
header: String,
author: String,
text: String
})
//compiling our schema into a Model
exports.post = settings.mongoose.model('post', postSchema)
Run Code Online (Sandbox Code Playgroud)
芯/ DB-layer.js
settings = require("./core/settings");
models = require("./core/models");
exports.function = createAndWriteNewPost(function(callback) {
settings.db.on('error', console.error.bind(console, 'connection error:'));
settings.db.once('open', function callback() {
new models.post({
header: 'header',
author: "author",
text: "Hello"
}).save(function(err, post) {
callback('ok');
});
});
});
Run Code Online (Sandbox Code Playgroud)
路线/ …
我正在尝试部署一个django项目.我尝试了很多教程,但没有运气.我使用一个新的干净的Ubuntu 11.10.我已经表演了
apt-get install nginx
apt-get install uwsgi
service nginx start
Run Code Online (Sandbox Code Playgroud)
我已经创建了文件夹/deploy/project1
并放在那里manage.py
和其他文件.
我目前/deploy/project1/project1/wsgi.py
包含:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project1.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Run Code Online (Sandbox Code Playgroud)
那么,你能告诉我如何domain.com
正确部署我的django应用程序吗?
我还通过pip和easy_install安装了Django
我应该加入/etc/nginx/sites-enabled/default
.
我正在使用Redux和React-router制作一个简单的Mail应用程序.由于我是Redux的新手,我不太了解Redux + Router中的实际数据流.
/
)之后,MailListComponent从服务器获取消息数组.此时不显示MessageComponent,因为它没有单个消息来为其获取数据.state.messages:[]
被取出,应用程序被导航到的所述第一消息state.messages:[]
(/messages/1
)`.这是组件模型:
// MailListActions.js
export function loadMessages() {
return {
type: 'LOAD_MESSAGES',
promise: client => client.get('/messages')
};
}
// MailListReducer.js
import Immutable from 'immutable';
const defaultState = { messages: [], fetchingMessages: false };
export default function mailListReducer(state = defaultState, action = {}) {
switch (action.type) {
case 'LOAD_MESSAGES_REQUEST':
return state.merge({fetchingMessages: true});
case …
Run Code Online (Sandbox Code Playgroud) 我的mongodb集合中有一个对象.它的架构是:
{
"instruments": ["A", "B", "C"],
"_id": {
"$oid": "508510cd6461cc5f61000001"
}
}
Run Code Online (Sandbox Code Playgroud)
我的收藏可能有这样的对象,但可能没有.我需要检查是否有关键的"乐器"对象存在(请notе,我不知道还有什么价值"仪器"就是在这个时候,它可能包含任何值或数组),如果存在-执行更新,否则 - 插入新值.我怎样才能做到这一点?
collection.find( { "instruments" : { $exists : true } }, function(err, object){
if (object) {
//update
} else {
//insert
}
});
Run Code Online (Sandbox Code Playgroud)
不起作用((
我正在编写一个带有身份验证的简单smtp-sender.这是我的代码
SMTPserver, sender, destination = 'smtp.googlemail.com', 'user@gmail.com', ['reciever@gmail.com']
USERNAME, PASSWORD = "user", "password"
# typical values for text_subtype are plain, html, xml
text_subtype = 'plain'
content="""
Hello, world!
"""
subject="Message Subject"
from smtplib import SMTP_SSL as SMTP # this invokes the secure SMTP protocol (port 465, uses SSL)
# from smtplib import SMTP # use this for standard SMTP protocol (port 25, no encryption)
from email.MIMEText import MIMEText
try:
msg = MIMEText(content, text_subtype)
msg['Subject']= subject
msg['From'] = sender # some …
Run Code Online (Sandbox Code Playgroud) 我有一个集合"公司"与几个对象.每个对象都有"_id"参数.我正试图从db获取此参数:
app.get('/companies/:id',function(req,res){
db.collection("companies",function(err,collection){
console.log(req.params.id);
collection.findOne({_id: req.params.id},function(err, doc) {
if (doc){
console.log(doc._id);
} else {
console.log('no data for this company');
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
所以,我要求公司/ 4fcfd7f246e1464d05000001(4fcfd7f246e1464d05000001是我需要的对象的_id-parma)并且findOne什么都不返回,这就是'为什么console.log('没有这家公司的数据'); 执行.
我绝对相信我有一个_id ="4fcfd7f246e1464d05000001"的对象.我做错了什么?谢谢!
但是,我刚刚注意到id不是典型的字符串字段.这就是mViewer所展示的:
"_id": {
"$oid": "4fcfd7f246e1464d05000001"
},
Run Code Online (Sandbox Code Playgroud)
似乎有点奇怪......
我已经读过这个话题Node.js + express.js + passport.js:在服务器重启之间保持身份验证,我需要完全相同的东西,但对于Redis.我用过这样的代码:
var RedisStore = require('connect-redis')(express);
app.use(express.session({
secret: "my secret",
store: new RedisStore,
cookie: { secure: true, maxAge:86400000 }
}));
Run Code Online (Sandbox Code Playgroud)
它不起作用.要连接Redis,我使用connect-redis模块.我做错了什么?谢谢!
UPD:我没有收到任何错误.为了成功确保身份验证过程,我添加了日志行,然后执行.
function(email, password, done) {
// asynchronous verification, for effect...
process.nextTick(function() {
findByEmail(email, function(err, user) {
if (!user) {
return done(null, false, {
message: 'Unknown user ' + email
});
}
if (user.password != password) {
return done(null, false, {
message: 'Invalid password'
});
}
//just logging that eveything seems fine
console.log("STATUS: User …
Run Code Online (Sandbox Code Playgroud) 我需要通过之前定义的Sequelize Model获取一些数据.
我需要的:
* attributes list
* attribute name
* attribute type (INTEGER, STRING,...)
* was it generated by association method?
* list of associations
* association type (belongsTo, hasMany, ...)
Run Code Online (Sandbox Code Playgroud)
出于某种原因,在控制台中检查Sequelize模型相当困难:
> db.sequelize.models.Payment
Payment // <- it's valid Sequelize Model {Object}, however its not inspectable
> db.sequelize.models.Payment.attributes
...
type:
{ type: { values: [Object] },
values: [ 'cash', 'account', 'transfer' ],
Model: Payment,
fieldName: 'type',
_modelAttribute: true,
field: 'type' },
sum:
{ type:
{ options: [Object],
_length: undefined,
_zerofill: …
Run Code Online (Sandbox Code Playgroud) node.js ×5
mongodb ×4
express ×2
mongoose ×2
architecture ×1
django ×1
email ×1
exists ×1
insert ×1
model ×1
nginx ×1
passport.js ×1
populate ×1
python ×1
react-router ×1
reactjs ×1
redirect ×1
redis ×1
redux ×1
sequelize.js ×1
session ×1
smtplib ×1
ubuntu-11.10 ×1
updates ×1
uwsgi ×1