You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a document. Argument is a plain JS object representing the document. It must contain a `_type` attribute. It *may* contain an `_id`. If an ID is not specified, it will automatically be created.
98
99
99
100
101
+
### Creating/replacing documents
102
+
103
+
```js
104
+
constdoc= {
105
+
_id:'my-bike',
106
+
_type:'bike',
107
+
name:'Bengler Tandem Extraordinaire',
108
+
seats:2
109
+
}
110
+
111
+
client.createOrReplace(doc).then(res=> {
112
+
console.log(`Bike was created, document ID is ${res._id}`)
113
+
})
114
+
```
115
+
116
+
`client.createOrReplace(doc)`
117
+
118
+
If you are not sure whether or not a document exists but want to overwrite it if it does, you can use the `createOrReplace()` method. When using this method, the document must contain an `_id` attribute.
119
+
120
+
### Creating if not already present
121
+
122
+
```js
123
+
constdoc= {
124
+
_id:'my-bike',
125
+
_type:'bike',
126
+
name:'Bengler Tandem Extraordinaire',
127
+
seats:2
128
+
}
129
+
130
+
client.createIfNotExists(doc).then(res=> {
131
+
console.log('Bike was created (or was already present)')
132
+
})
133
+
```
134
+
135
+
`client.createIfNotExists(doc)`
136
+
137
+
If you want to create a document if it does not already exist, but fall back without error if it does, you can use the `createIfNotExists()` method. When using this method, the document must contain an `_id` attribute.
0 commit comments