Schema.add 方法是用于向数据库中的集合(collection)添加一个新的文档(document)的方法。它的用法如下:

db.collection('collectionName').add(data)

其中,collectionName是要添加文档的集合的名称,data是要添加的文档数据。

示例:

const admin = require('firebase-admin');

admin.initializeApp();

const db = admin.firestore();

const data = {
  name: 'John',
  age: 30,
  email: 'john@example.com'
};

db.collection('users').add(data)
  .then((docRef) => {
    console.log('Document added with ID: ', docRef.id);
  })
  .catch((error) => {
    console.error('Error adding document: ', error);
  });

上述代码将向名为 "users" 的集合中添加一个文档,文档数据为 data 对象。添加成功后,会返回一个 DocumentReference 对象,可以通过 docRef.id 获取新添加文档的 ID。如果添加失败,会打印出错误信息

Schemaadd 怎么用

原文地址: http://www.cveoy.top/t/topic/hZLt 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录