我的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)
不起作用((
我知道堆栈溢出有相同/类似的问题,我也阅读了文档 - 我仍然不明白任何 - 如何设置这些变量和WHERE !! 设置它们.
我的env/production.js文件:
module.exports = {
"DATABASE_URI": process.env.DATABASE_URI,
"SESSION_SECRET": process.env.SESSION_SECRET,
"TWITTER": {
"consumerKey": process.env.TWITTER_CONSUMER_KEY,
"consumerSecret": process.env.TWITTER_CONSUMER_SECRET,
"callbackUrl": process.env.TWITTER_CALLBACK
},
"FACEBOOK": {
"clientID": process.env.FACEBOOK_APP_ID,
"clientSecret": process.env.FACEBOOK_CLIENT_SECRET,
"callbackURL": process.env.FACEBOOK_CALLBACK_URL
},
"GOOGLE": {
"clientID": process.env.GOOGLE_CLIENT_ID,
"clientSecret": process.env.GOOGLE_CLIENT_SECRET,
"callbackURL": process.env.GOOGLE_CALLBACK_URL
},
"LOGGING": true
};
Run Code Online (Sandbox Code Playgroud)
在我的env/development.js文件中,我设置了变量(链接到我的postgres/localhost/xxx).我是否需要将它们设置为heroku(Google,Facebook等)或仅用于数据库,因为我必须使用heroku创建一个?我是否将链接保留在我的开发文件中的本地数据库中并单独链接到heroku数据库?
我甚至不知道我是否想从我的命令行中做到这一点?!在文档中它说:heroku config:get CONFIG-VAR-NAME -s >> .env所以它是heroku配置:获取我的HEROKU DATABASE的配置名称-s >> .env?
我是第一次部署而且很困惑!救命 :)
我已经安装了proxyquire,我的ajax.test.tsx文件包含以下代码,只有2行
import * as proxyquire from 'proxyquire';
proxyquire.noCallThru();
Run Code Online (Sandbox Code Playgroud)
我的webpack代码如下
module.exports = {
entry: {
"book.service": './src/book.service.ts',
"ajax.test": './src/ajax.test.tsx'
},
output: {
filename: "[name].js",
path: __dirname + "/dist"
},
devtool: "source-map",
watch: true,
resolve: {
extensions: [".tsx", ".tsx", ".js", ".json", ".ts", '.d.ts']
},
module: {
rules: [
{ test: /\.tsx?$/, loader: "awesome-typescript-loader" },
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
]
},
externals: {
'react/lib/ExecutionEnvironment': true,
'react/addons': true,
'react/lib/ReactContext': 'window'
}
};
Run Code Online (Sandbox Code Playgroud)
我安装了proxyquire&@ types/proxyquire.当我运行webpack命令时,它会抛出以下错误
WARNING in ./~/proxyquire/lib/proxyquire.js
require.extensions is not …Run Code Online (Sandbox Code Playgroud) 我刚开始玩猫鼬和mongo.我有以下代码:
var ninjaSchema = mongoose.Schema({
name: String,
skill: Number
});
var Ninja = mongoose.model('Ninja',ninjaSchema);
module.exports = {
init : function(){
console.log('Connecting to database');
mongoose.connect('mongodb://localhost/mydb');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function callback () {
console.log('Successfully connected!');
});
},
createNinja : function(name,skill){
var n = new Ninja({name:name,skill:skill});
n.save(function(err,n){
if (err)
console.log('saving failed');
console.log('saved '+ n.name);
});
},
getNinjas : function(){
var res = null;
res = Ninja.findOne({},'name skill',function(err,docs){
if (err)
console.log('error occured in the query');
return 'ninja name: …Run Code Online (Sandbox Code Playgroud) 我有mongoose架构:
var Organization = new Schema({
name: String,
address: {
street : String,
city: String
}
}, { collection: 'organization' });
Run Code Online (Sandbox Code Playgroud)
如何通过mongoose仅更新组织的街道部分地址?
几年前,我在免费网站上添加了一个自定义域名,以尝试Github的新功能.现在我想创建一个页面,我的主网址不断重定向到myexpireddomain.com ...
http://myuser.github.io => myexpireddomain.com
http://myuser.github.io/page => myexpireddomain.com/page
Run Code Online (Sandbox Code Playgroud)
这一切都导致了404 ...因为域名不存在.
我想我需要在某处删除cname文件.但是,我有20个回购,我没有看到任何应该cname ...哪个回购在根域.http://myuser.github.io
我有嵌入式文档更新的问题.
我定义的架构:
var Talk = new Schema({
title: {
type: String,
required: true
},
content: {
type: String,
required: true
},
date: {
type: Date,
required: true
},
comments: {
type: [Comments],
required: false
},
vote: {
type: [VoteOptions],
required: false
},
});
var VoteOptions = new Schema({
option: {
type: String,
required: true
},
count: {
type: Number,
required: false
}
});
Run Code Online (Sandbox Code Playgroud)
现在我想vote.count++用给定的Talkid和VoteOptionid 更新.我有以下功能来完成这项工作:
function makeVote(req, res) {
Talk.findOne(req.params.id, function(err, talk) {
for …Run Code Online (Sandbox Code Playgroud) 如果在执行期间将项目添加到使用渲染的数组中ngRepeat,是否重绘所有项目?
我已经浏览了mongoose API,以及关于SO和google组的许多问题,但仍无法弄清楚更新嵌入式文档.
我正在尝试使用args的内容更新此特定的userListings对象.
for (var i = 0; i < req.user.userListings.length; i++) {
if (req.user.userListings[i].listingId == req.params.listingId) {
User.update({
_id: req.user._id,
'userListings._id': req.user.userListings[i]._id
}, {
'userListings.isRead': args.isRead,
'userListings.isFavorite': args.isFavorite,
'userListings.isArchived': args.isArchived
}, function(err, user) {
res.send(user);
});
}
}
Run Code Online (Sandbox Code Playgroud)
以下是架构:
var userListingSchema = new mongoose.Schema({
listingId: ObjectId,
isRead: {
type: Boolean,
default: true
},
isFavorite: {
type: Boolean,
default: false
},
isArchived: {
type: Boolean,
default: false
}
});
var userSchema = new mongoose.Schema({
userListings: [userListingSchema]
});
Run Code Online (Sandbox Code Playgroud)
这个发现也行不通,这可能是第一个问题:
User.find({
'_id': …Run Code Online (Sandbox Code Playgroud) 我正在使用GitHub页面来托管我的博客.我在存储库中设置了CNAME记录,并将A记录和CNAME记录添加到我的域名注册商(123-reg).这工作正常,所以现在我的个人页面donskifarrell.github.com - > donalfarrell.com.
这也使我的所有项目页面都映射到同一个新域,例如.donskifarrell.github.com/calex - > donalfarrell.com/calex.
虽然这是非常好的,但事实证明这对我的一个项目来说很麻烦.
有没有办法修改我的设置,以便某些项目页面不使用我自己的自定义域,而是保留github网址?
谢谢
mongodb ×5
node.js ×5
mongoose ×4
github ×2
angularjs ×1
cname ×1
config ×1
dns ×1
exists ×1
express ×1
github-pages ×1
heroku ×1
insert ×1
javascript ×1
proxyquire ×1
reactjs ×1
typescript ×1
updates ×1
webpack ×1