mongodb

Like search into MongoDB with Monk library

寵の児 提交于 2021-02-10 20:44:42
问题 I'm trying to do like search into mongodb with Javascript, but i havent yet figured it out how to do it. Any help is appreciated. I have a search parameter called "search" at request body (req.body.search). I would like find all programs which name contains that search criteria. Ie. "harry" would return " Harry Potter", "Potter Harry ", "How merry Harry Really is?" and other movies which contains harry in its name. exports.programs = function(db, req) { return function(req, res) { var

Error getting MongoDB by _Id in Flask

北城余情 提交于 2021-02-10 20:22:43
问题 I can query my MongoDB and I see the "_id" value like this: "_id" : BinData(3,"sFgVQWMKzUiWl5dql62j2g==") Using Flask 0.10.1 and PyMongo 3.0.3 I attempt to "find_one" like this: record = db.collection.find_one({'_id': ObjectId("sFgVQWMKzUiWl5dql62j2g==")}) And I get this error: bson.errors.InvalidId: 'sFgVQWMKzUiWl5dql62j2g==' is not a valid ObjectId, it must be a 12-byte input or a 24-character hex string Any help would be appreciated. 回答1: You are storing _id as bindata and trying to

Unable to connect to MongoDB Atlas using Mongoose with connection string [closed]

可紊 提交于 2021-02-10 20:18:51
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 1 year ago . Improve this question These are the errors I received: (node:11692) UnhandledPromiseRejectionWarning: MongoNetworkError: connection 5 to cluster0-shard-00-01-wwvto.mongodb.net:27017 closed at TLSSocket. (C:\Node Example\node-rest-shop\node_modules\mongodb-core\lib\connection\connection.js:276:9) at

Mongoose & Express: How to properly Remove, Create & Store data that are reference

混江龙づ霸主 提交于 2021-02-10 20:10:46
问题 The first problem I am having is that whenever I try to delete the Comment, I also try to find the index of that specific comment inside post.comments as well as inside user.comments , it consistently returns -1, the reason why I am trying to find it, is so that I can splice it from the comments array that user and post do have. The second problem I am having is that whenever I create a comment, I try to store it in the comments array that user and post have, but it stores it only as a string

Mongoose & Express: How to properly Remove, Create & Store data that are reference

心不动则不痛 提交于 2021-02-10 20:10:20
问题 The first problem I am having is that whenever I try to delete the Comment, I also try to find the index of that specific comment inside post.comments as well as inside user.comments , it consistently returns -1, the reason why I am trying to find it, is so that I can splice it from the comments array that user and post do have. The second problem I am having is that whenever I create a comment, I try to store it in the comments array that user and post have, but it stores it only as a string

React: use axios to post state to MongoDB

心不动则不痛 提交于 2021-02-10 19:33:18
问题 I am trying to post the states as data to MongoDB through Express and Node with Axios. class App extends React.Component { constructor(props){ super(props) this.state={ items: [{ desc:"Manage", price: 5000, purchased: false, }, { desc:"Deliver", price: 2000, purchased: false, }, { desc:"Market", price: 4000, purchased: false, } ], data:null, DisabledButton: true } } getAddedItems(){ return this.state.items.filter(item => item.purchased) } componentDidMount() { this.callApi() .then(res => this

React: use axios to post state to MongoDB

自古美人都是妖i 提交于 2021-02-10 19:32:22
问题 I am trying to post the states as data to MongoDB through Express and Node with Axios. class App extends React.Component { constructor(props){ super(props) this.state={ items: [{ desc:"Manage", price: 5000, purchased: false, }, { desc:"Deliver", price: 2000, purchased: false, }, { desc:"Market", price: 4000, purchased: false, } ], data:null, DisabledButton: true } } getAddedItems(){ return this.state.items.filter(item => item.purchased) } componentDidMount() { this.callApi() .then(res => this

React: use axios to post state to MongoDB

柔情痞子 提交于 2021-02-10 19:32:13
问题 I am trying to post the states as data to MongoDB through Express and Node with Axios. class App extends React.Component { constructor(props){ super(props) this.state={ items: [{ desc:"Manage", price: 5000, purchased: false, }, { desc:"Deliver", price: 2000, purchased: false, }, { desc:"Market", price: 4000, purchased: false, } ], data:null, DisabledButton: true } } getAddedItems(){ return this.state.items.filter(item => item.purchased) } componentDidMount() { this.callApi() .then(res => this

How to avoid two concurrent API requests breaking the logic behind document validation?

♀尐吖头ヾ 提交于 2021-02-10 18:56:21
问题 I have an API that in order to insert a new item it needs to be validated. The validation basically is a type validator( string , number , Date , e.t.c) and queries the database that checks if the "user" has an "item" in the same date, which if it does the validation is unsuccessful. Pseudocode goes like this: const Item = require("./models/item"); function post(newDoc){ let errors = await checkForDocErrors(newDoc) if (errors) { throw errors; } let itemCreated = await Item.create(newDoc);

How to avoid two concurrent API requests breaking the logic behind document validation?

非 Y 不嫁゛ 提交于 2021-02-10 18:54:43
问题 I have an API that in order to insert a new item it needs to be validated. The validation basically is a type validator( string , number , Date , e.t.c) and queries the database that checks if the "user" has an "item" in the same date, which if it does the validation is unsuccessful. Pseudocode goes like this: const Item = require("./models/item"); function post(newDoc){ let errors = await checkForDocErrors(newDoc) if (errors) { throw errors; } let itemCreated = await Item.create(newDoc);