我正在尝试操作一个JSON,它不是我创建的,只是上传到了mongo。在NodeJs中,我正在尝试:
app.get('/municipios', async (req, res) => {
let cidadeSchema = new Schema({}, { strict: false })
let cidades = mongoose.model('municipios', cidadeSchema)
let cidade = cidades.findOne({name: 'Rio Grande'})
// consol
我正在尝试使用Mongoose更新MongoDB中的一个对象,但我得到的是错误TypeError: course.save is not a function。我可以创建并找到“课程”对象。
我完全遵循了课程中的说明,并试图排除故障,但没有效果!
知道这是怎么回事吗?
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/playground', {
useNewUrlParser: true
})
.then(() => c
我对node完全陌生,它是框架Koa和express。我有一个叫做绘图的猫鼬模型和一个路由器模块。
问题是对于快速路由器,我能够使用Drawing.find方法从数据库中获取数据,但是使用Koa,控件甚至没有进入Drawing.find。我根本无法得到数据。请找到以下相关代码,并帮助我更好地理解事情。
这是我的路由器模块
import * as Router from "koa-router";
import Drawing from "../../models/drawing";
function getRoutesForDrawing(): Router
保存函数工作得很好,但是在搜索之前保存的保存对象时,它下面的find函数返回null。以下是代码:
var mongoose = require("mongoose");
var User = mongoose.model("User");
module.exports.register = function(req, res) {
var user = new User();
user.name = req.body.name;
user.email = req.body.email;
user.setPassword(req.body.pa
我正在使用mongo 4.4.10 (由于语法限制) Express、mongoose和UniqueValidator 3.0.0 (主要嫌疑人)
做这件事的时候
router.get('/test',async (req,res)=>{
try {
const user = await UserModel.findById('abc'); //it find the user with id abc
user.firstname = 'testOk';
await use
我正在尝试使用模型和模式从mongo中获取所有记录。我能连接到db。当我运行查询时,我没有得到任何响应。
routes.js
import express from 'express';
var router = express.Router();
import mongoose from 'mongoose';
const db = 'mongodb://localhost:27017/dbname';
import {contacts} from '../models/model.js';
// exports this j
我试图使用findOne属性从集合中获取一个用户,但是它返回的是未定义的,而我的用户在db中。
这是我的模式:
var schema = new mongoose.Schema({
name: {
type: String,
required: [true, "Please enter a name"],
maxlength: 32,
},
password: {
type: String,
required: true,
minlength: [6, "Password must be at least 6
我不会进入对save()或find()方法的回调。它也没有进入mongoose.connect的回调。知道为什么吗?
这是我的密码:
mongoose.connect("mongodb://localhost/blah", {
useMongoClient: true,
}, function (err) {
console.log('connect to database'); // Not called
if (err) {
throw err;
}
});
var Schema = mongoose.Sch
我使用nodejs作为服务器,向mongodb发送参数,然后将其保存在数据库中,然后从数据库中获取它。但是,当我试图获取数据时,我无法看到nodejs终端中的当前数据,但它将出现在数据库中。同样,如果我发送其他数据,我将能够看到以前的数据,而不是我现在发送的当前数据。我认为我的服务器在保存函数之前调用了find函数。我应该做什么来使我的保存函数完成它的任务,然后它应该调用find函数。
这个mongodb代码从‘猫鼬’中导入猫鼬;
var Schema = mongoose.Schema;
//connect to a MongoDB database
var db = mongoose.co