使用循环在猫鼬中添加数据

时间:2018-10-28 18:47:02

标签: node.js reactjs mongodb mongoose

我有一个看起来像这样的猫鼬模式

tbl_prima_nota

现在,我正在从节点应用程序的前端获取数据,需要将其存储在数据库中。

我的前端数据恰好具有与猫鼬模式相同的密钥

let mongoose = require("mongoose");

let UserData = new mongoose.Schema ({
    userid: String,
    phone: String,
    address: String,
    state: String,
    city: String,
    pinCode: String, 
    primarySports: String,
    bestAchievement: String, 
    role: String,
    role1: String,
    secondaySports: String, 
    bio: String,
    dob: String
  });

  module.exports = mongoose.model("user", UserData);

现在,不要像这样通过手动操作来存储数据

state = {
  bestAchievement: "",
  secondaySports: "",
  dob: "",
  primarySports: "",
  role: "",
  role1: "",
  phone: "",
  userid: "",
  address: "",
  state: "",
  city: "",
  pinCode: "",
  bio: ""
}

我当时正在考虑运行new User({ username: profile.displayName, userId: profile.id, image: newURL, email: profile.emails[0]["value"] } 循环或for-in,但是我不确定该怎么做。

问题:有人可以帮助我们弄清楚如何使用循环在猫鼬中添加日期吗?

0 个答案:

没有答案