how to save multiple for loops data?How to send headers after loopHow to query MongoDB with “like”?How to retrieve POST query parameters?ExpressJS How to structure an application?How to get GET (query string) variables in Express.js on Node.js?How to allow CORS?Mongod complains that there is no /data/db folderHow do I drop a MongoDB database from the command line?How to list all collections in the mongo shell?“Large data” work flows using pandasInsert geojson polygons into mongodb and query, based on the coordinates of a point, all the polygons which are located at a certain distance from it
Is there metaphorical meaning of "aus der Haft entlassen"?
A strange hotel
Do I need to watch Ant-Man and the Wasp and Captain Marvel before watching Avengers: Endgame?
Von Neumann Extractor - Which bit is retained?
How much of a wave function must reside inside event horizon for it to be consumed by the black hole?
A Paper Record is What I Hamper
Is Diceware more secure than a long passphrase?
What is the unit of time_lock_delta in LND?
Why do distances seem to matter in the Foundation world?
Why do games have consumables?
Drawing a german abacus as in the books of Adam Ries
How can I practically buy stocks?
Who's the random kid standing in the gathering at the end?
Cayley's Matrix Notation
What was Apollo 13's "Little Jolt" after MECO?
SFDX - Create Objects with Custom Properties
Contradiction proof for inequality of P and NP?
Will I lose my paid in full property
How important is it that $TERM is correct?
What *exactly* is electrical current, voltage, and resistance?
How to have a sharp product image?
A faster way to compute the largest prime factor
How do I reattach a shelf to the wall when it ripped out of the wall?
"The cow" OR "a cow" OR "cows" in this context
how to save multiple for loops data?
How to send headers after loopHow to query MongoDB with “like”?How to retrieve POST query parameters?ExpressJS How to structure an application?How to get GET (query string) variables in Express.js on Node.js?How to allow CORS?Mongod complains that there is no /data/db folderHow do I drop a MongoDB database from the command line?How to list all collections in the mongo shell?“Large data” work flows using pandasInsert geojson polygons into mongodb and query, based on the coordinates of a point, all the polygons which are located at a certain distance from it
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
In Post request, I want to pull objectId's data and save it in the database. There will be 2 or 3 objectId's which will I will be getting it in array. From that array I am able to pull the data with separate "for loops" but at the end I am not able to save the data.
I want to know how to move data from one array to another or directly save the data.
Schema:--
const jobSch = new Schema(
token : type:Number,
name : type:String,
phoneNumber: type:Number,
gender : type:String,
stage : type:String,
categoryId : [Schema.Types.ObjectId],
subCategoryId : [Schema.Types.ObjectId],
serviceId : [Schema.Types.ObjectId],
category : [String],
subcategory : [String],
service: [String],
paymenttype: [String],
tax: type:Number,
totalprice: type:String,
servicePerson: type:String,
createdOn : type:Date, default:new Date(),
updatedOn : type:Date, default:new Date()
);
POST request code:--
router.post('/', async (req, res) =>
let ids = req.body;
let catId = ids.categoryId;
console.log("catId", catId)
console.log("catId.length", catId.length)
let subcatId = ids.subCategoryId;
console.log("subcatId", subcatId);
console.log("subcatId.length", subcatId.length)
let serId = ids.serviceId;
console.log("serId", serId);
console.log("subcatId.length", serId.length)
let job = new Job(ids);
let catgy=[];
let subcatgy=[];
let subser=[];
for (i = 0; i < catId.length; i++)
Category.findById(catId[i])
.then(category =>
if (category && category != null)
console.log('category.name', category.name);
catgy.push(`$category.name`)
console.log(catgy);
)
for (i = 0; i < subcatId.length; i++)
Service.findById(subcatId[i])
.then(service =>
if (service && service != null)
console.log('service.name', service.name);
subcatgy.push(`$service.name`)
console.log(subcatgy);
)
for (i = 0; i < serId.length; i++)
Subservice.findById(serId[i])
.then(subService =>
if (subService && subService != null)
console.log('subservice.name', subService.subService);
subser.push(`$subService.subService`)
console.log(subser);
)
var category = catgy.slice();
console.log("category1", category)
var service = subcatgy.slice();
console.log('service2', service);
var subService = subser.slice();
console.log('subService3',subService);
console.log(job);
job.save().then(job =>
res.status(201).json(
message: 'Job saved successfully', job
)
).catch(err => console.log(err));
);
mongodb api express mongoose-schema
add a comment |
In Post request, I want to pull objectId's data and save it in the database. There will be 2 or 3 objectId's which will I will be getting it in array. From that array I am able to pull the data with separate "for loops" but at the end I am not able to save the data.
I want to know how to move data from one array to another or directly save the data.
Schema:--
const jobSch = new Schema(
token : type:Number,
name : type:String,
phoneNumber: type:Number,
gender : type:String,
stage : type:String,
categoryId : [Schema.Types.ObjectId],
subCategoryId : [Schema.Types.ObjectId],
serviceId : [Schema.Types.ObjectId],
category : [String],
subcategory : [String],
service: [String],
paymenttype: [String],
tax: type:Number,
totalprice: type:String,
servicePerson: type:String,
createdOn : type:Date, default:new Date(),
updatedOn : type:Date, default:new Date()
);
POST request code:--
router.post('/', async (req, res) =>
let ids = req.body;
let catId = ids.categoryId;
console.log("catId", catId)
console.log("catId.length", catId.length)
let subcatId = ids.subCategoryId;
console.log("subcatId", subcatId);
console.log("subcatId.length", subcatId.length)
let serId = ids.serviceId;
console.log("serId", serId);
console.log("subcatId.length", serId.length)
let job = new Job(ids);
let catgy=[];
let subcatgy=[];
let subser=[];
for (i = 0; i < catId.length; i++)
Category.findById(catId[i])
.then(category =>
if (category && category != null)
console.log('category.name', category.name);
catgy.push(`$category.name`)
console.log(catgy);
)
for (i = 0; i < subcatId.length; i++)
Service.findById(subcatId[i])
.then(service =>
if (service && service != null)
console.log('service.name', service.name);
subcatgy.push(`$service.name`)
console.log(subcatgy);
)
for (i = 0; i < serId.length; i++)
Subservice.findById(serId[i])
.then(subService =>
if (subService && subService != null)
console.log('subservice.name', subService.subService);
subser.push(`$subService.subService`)
console.log(subser);
)
var category = catgy.slice();
console.log("category1", category)
var service = subcatgy.slice();
console.log('service2', service);
var subService = subser.slice();
console.log('subService3',subService);
console.log(job);
job.save().then(job =>
res.status(201).json(
message: 'Job saved successfully', job
)
).catch(err => console.log(err));
);
mongodb api express mongoose-schema
i got a different solution for pushing the data.. But thanks the link which u had give gave me a rough idea!!! @RenatoVassao
– user10009323
Mar 11 at 10:55
add a comment |
In Post request, I want to pull objectId's data and save it in the database. There will be 2 or 3 objectId's which will I will be getting it in array. From that array I am able to pull the data with separate "for loops" but at the end I am not able to save the data.
I want to know how to move data from one array to another or directly save the data.
Schema:--
const jobSch = new Schema(
token : type:Number,
name : type:String,
phoneNumber: type:Number,
gender : type:String,
stage : type:String,
categoryId : [Schema.Types.ObjectId],
subCategoryId : [Schema.Types.ObjectId],
serviceId : [Schema.Types.ObjectId],
category : [String],
subcategory : [String],
service: [String],
paymenttype: [String],
tax: type:Number,
totalprice: type:String,
servicePerson: type:String,
createdOn : type:Date, default:new Date(),
updatedOn : type:Date, default:new Date()
);
POST request code:--
router.post('/', async (req, res) =>
let ids = req.body;
let catId = ids.categoryId;
console.log("catId", catId)
console.log("catId.length", catId.length)
let subcatId = ids.subCategoryId;
console.log("subcatId", subcatId);
console.log("subcatId.length", subcatId.length)
let serId = ids.serviceId;
console.log("serId", serId);
console.log("subcatId.length", serId.length)
let job = new Job(ids);
let catgy=[];
let subcatgy=[];
let subser=[];
for (i = 0; i < catId.length; i++)
Category.findById(catId[i])
.then(category =>
if (category && category != null)
console.log('category.name', category.name);
catgy.push(`$category.name`)
console.log(catgy);
)
for (i = 0; i < subcatId.length; i++)
Service.findById(subcatId[i])
.then(service =>
if (service && service != null)
console.log('service.name', service.name);
subcatgy.push(`$service.name`)
console.log(subcatgy);
)
for (i = 0; i < serId.length; i++)
Subservice.findById(serId[i])
.then(subService =>
if (subService && subService != null)
console.log('subservice.name', subService.subService);
subser.push(`$subService.subService`)
console.log(subser);
)
var category = catgy.slice();
console.log("category1", category)
var service = subcatgy.slice();
console.log('service2', service);
var subService = subser.slice();
console.log('subService3',subService);
console.log(job);
job.save().then(job =>
res.status(201).json(
message: 'Job saved successfully', job
)
).catch(err => console.log(err));
);
mongodb api express mongoose-schema
In Post request, I want to pull objectId's data and save it in the database. There will be 2 or 3 objectId's which will I will be getting it in array. From that array I am able to pull the data with separate "for loops" but at the end I am not able to save the data.
I want to know how to move data from one array to another or directly save the data.
Schema:--
const jobSch = new Schema(
token : type:Number,
name : type:String,
phoneNumber: type:Number,
gender : type:String,
stage : type:String,
categoryId : [Schema.Types.ObjectId],
subCategoryId : [Schema.Types.ObjectId],
serviceId : [Schema.Types.ObjectId],
category : [String],
subcategory : [String],
service: [String],
paymenttype: [String],
tax: type:Number,
totalprice: type:String,
servicePerson: type:String,
createdOn : type:Date, default:new Date(),
updatedOn : type:Date, default:new Date()
);
POST request code:--
router.post('/', async (req, res) =>
let ids = req.body;
let catId = ids.categoryId;
console.log("catId", catId)
console.log("catId.length", catId.length)
let subcatId = ids.subCategoryId;
console.log("subcatId", subcatId);
console.log("subcatId.length", subcatId.length)
let serId = ids.serviceId;
console.log("serId", serId);
console.log("subcatId.length", serId.length)
let job = new Job(ids);
let catgy=[];
let subcatgy=[];
let subser=[];
for (i = 0; i < catId.length; i++)
Category.findById(catId[i])
.then(category =>
if (category && category != null)
console.log('category.name', category.name);
catgy.push(`$category.name`)
console.log(catgy);
)
for (i = 0; i < subcatId.length; i++)
Service.findById(subcatId[i])
.then(service =>
if (service && service != null)
console.log('service.name', service.name);
subcatgy.push(`$service.name`)
console.log(subcatgy);
)
for (i = 0; i < serId.length; i++)
Subservice.findById(serId[i])
.then(subService =>
if (subService && subService != null)
console.log('subservice.name', subService.subService);
subser.push(`$subService.subService`)
console.log(subser);
)
var category = catgy.slice();
console.log("category1", category)
var service = subcatgy.slice();
console.log('service2', service);
var subService = subser.slice();
console.log('subService3',subService);
console.log(job);
job.save().then(job =>
res.status(201).json(
message: 'Job saved successfully', job
)
).catch(err => console.log(err));
);
mongodb api express mongoose-schema
mongodb api express mongoose-schema
asked Mar 9 at 7:40
user10009323user10009323
12
12
i got a different solution for pushing the data.. But thanks the link which u had give gave me a rough idea!!! @RenatoVassao
– user10009323
Mar 11 at 10:55
add a comment |
i got a different solution for pushing the data.. But thanks the link which u had give gave me a rough idea!!! @RenatoVassao
– user10009323
Mar 11 at 10:55
i got a different solution for pushing the data.. But thanks the link which u had give gave me a rough idea!!! @RenatoVassao
– user10009323
Mar 11 at 10:55
i got a different solution for pushing the data.. But thanks the link which u had give gave me a rough idea!!! @RenatoVassao
– user10009323
Mar 11 at 10:55
add a comment |
1 Answer
1
active
oldest
votes
The problem is that the callback function of the resolved promises (findById
) are executed asynchronously. Try checking this out, I think it will help you.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55075129%2fhow-to-save-multiple-for-loops-data%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The problem is that the callback function of the resolved promises (findById
) are executed asynchronously. Try checking this out, I think it will help you.
add a comment |
The problem is that the callback function of the resolved promises (findById
) are executed asynchronously. Try checking this out, I think it will help you.
add a comment |
The problem is that the callback function of the resolved promises (findById
) are executed asynchronously. Try checking this out, I think it will help you.
The problem is that the callback function of the resolved promises (findById
) are executed asynchronously. Try checking this out, I think it will help you.
answered Mar 9 at 14:11
Renato VassãoRenato Vassão
1015
1015
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55075129%2fhow-to-save-multiple-for-loops-data%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
i got a different solution for pushing the data.. But thanks the link which u had give gave me a rough idea!!! @RenatoVassao
– user10009323
Mar 11 at 10:55