CRUD - 创建 - Node.js SDK
在此页面上
Realm 现已更名为 Atlas Device SDK – 了解详情
创建新对象
要将对象添加到 Realm,请像实例化任何其他对象一样实例化该对象,然后将其传递给写事务内的Realm.create() 。如果 Realm 的模式包含对象类型,并且对象符合该模式,则 Realm 会存储该对象,该对象现在由 Realm托管。
// Declare the variable that will hold the dog instance. let dog; // Open a transaction. realm.write(() => { // Assign a newly-created instance to the variable. dog = realm.create("Dog", { name: "Max", age: 5 }); }); // use newly created dog object