我在这里问过这个问题,但没有一个答案对我有用.
我的代码:
var BSON = require('mongodb').BSONPure;
// value is 544d644cf6eea12336f5e0a1
var object_id = BSON.ObjectID.createFromHexString(req.params.id);
}
// Create GET _id query
collection.find(object_id).toArray(
function (err, data) {
if (!err) {
// 200 OK
return res.status(200).send({success: true, code: 200, count: data.length, results: data});
} else {
// 500 Internal Server (Mongodb)
console.log(err);
return res.status(500).send({success: false, code: 500, error: "Internal Server Error"});
}
Run Code Online (Sandbox Code Playgroud)
我试过通过ObjectId找到五种不同的方法,但没有一种方法可以工作.以上是我最近的尝试.我没有得到Node的结果.在我做的时候在mongo shell里面:
> db.people.find({_id : ObjectId("544d644cf6eea12336f5e0a1")});
{ "_id" : ObjectId("544d644cf6eea12336f5e0a1"), "name" : "Jim", "age" : 24, "job" : "engineer" }
Run Code Online (Sandbox Code Playgroud)
如你所见,我得到了一个结果.我在这里错过了什么?
您好我是NodeJs的新手,我一直在关注本教程http://code.tutsplus.com/tutorials/authenticating-nodejs-applications-with-passport--cms-21619来创建一个带有身份验证的应用程序.我试图遵循教程中的所有结构和代码(代码在github上https://github.com/tutsplus/passport-mongo)但是当我在浏览器中打开我的应用程序时出现错误此错误
TypeError:passport.authenticate不是module.exports的函数(C:\ myApp\routes\index.js:24:34)
这是我的index.js路由文件
var express = require('express');
var router = express.Router();
var passport = require('passport');
var isAuthenticated = function (req, res, next) {
// if user is authenticated in the session, call the next() to call the next request handler
// Passport adds this method to request object. A middleware is allowed to add properties to
// request and response objects
if (req.isAuthenticated())
return next();
// if the user is not authenticated then redirect him …Run Code Online (Sandbox Code Playgroud) 我试图循环一片函数,然后调用其中的每个函数.但是我得到了奇怪的结果.这是我的代码:
package main
import (
"fmt"
"sync"
)
func A() {
fmt.Println("A")
}
func B() {
fmt.Println("B")
}
func C() {
fmt.Println("C")
}
func main() {
type fs func()
var wg sync.WaitGroup
f := []fs{A, B, C}
for a, _ := range f {
wg.Add(1)
go func() {
defer wg.Done()
f[a]()
}()
}
wg.Wait()
}
Run Code Online (Sandbox Code Playgroud)
我以为它会调用函数A,B然后调用C但是我的输出只得到Cs.
C
C
C
Run Code Online (Sandbox Code Playgroud)
请提出错误及其背后的逻辑.我怎样才能获得理想的行为.
我公开发布了一个包,我试图在 npm ( https://www.npmjs.com/ )上搜索它,但是npm上没有该名称的包。
尝试过:
npm install package-name -> 工作正常
这是包链接:
https://www.npmjs.com/package/and-or-search
有什么我想念的吗?
由于 MongoDB 3.x 为每条记录而不是集合或数据库引入了锁,因此将所有数据写入具有一个额外标识符字段“documentType”的单个集合是否有意义。它将有助于通过 map-reduce 操作模拟“加入”。Couchbase 使用“buckets”而不是集合做同样的事情。
有人看到这种方法有什么缺点吗?
node.js ×3
mongodb ×2
go ×1
goroutine ×1
javascript ×1
npm ×1
npm-publish ×1
package ×1
passport.js ×1
slice ×1