Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 34 additions & 31 deletions getting-started/nodejs-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,48 +62,51 @@ const { MongoClient } = require('mongodb');
const uri = 'mongodb://<YOUR_USERNAME>:<YOUR_PASSWORD>@localhost:10260/?tls=true&tlsAllowInvalidCertificates=true';
const client = new MongoClient(uri);

async function connect() {
try {
await client.connect();
const db = client.db('your_database');
return db;
} catch (error) {
console.error('Connection error:', error);
throw error;
}
async function main() {
await client.connect();
const db = client.db('your_database');
console.log('connected');
return db;
}

main().catch((error) => {
console.error('Connection error:', error);
process.exit(1);
});
```

## Basic Operations

1. Creating collections
```javascript
const collection = db.collection('your_collection');
```

2. Document operations
The operations below all run inside `main()`, after `const db = client.db(...)` above.
`await` is only valid inside an `async` function, and `db` only exists in that scope —
running these at the top level of a file gives `ReferenceError: db is not defined`.

```javascript
const users = db.collection('users');
```javascript
async function main() {
await client.connect();
const db = client.db('your_database');
const users = db.collection('users');

await users.insertOne({ name: 'John Doe', email: 'john@example.com', createdAt: new Date() });
await users.insertMany([
{ name: 'Jane Smith', email: 'jane@example.com' },
{ name: 'Bob Johnson', email: 'bob@example.com' },
]);
await users.insertOne({ name: 'John Doe', email: 'john@example.com', createdAt: new Date() });
await users.insertMany([
{ name: 'Jane Smith', email: 'jane@example.com' },
{ name: 'Bob Johnson', email: 'bob@example.com' },
]);

await users.updateOne({ name: 'John Doe' }, { $set: { status: 'active' } });
console.log(await users.findOne({ name: 'John Doe' }));
console.log(await users.countDocuments());
await users.updateOne({ name: 'John Doe' }, { $set: { status: 'active' } });
console.log(await users.findOne({ name: 'John Doe' }));
console.log(await users.countDocuments());

await users.deleteOne({ name: 'Bob Johnson' });
```
await users.deleteOne({ name: 'Bob Johnson' });

Always close the client when the process is done:
await client.close();
}

```javascript
await client.close();
```
main().catch((error) => {
console.error(error);
process.exit(1);
});
```

## Beyond CRUD

Expand Down
27 changes: 26 additions & 1 deletion getting-started/python-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,32 @@ DocumentDB Local accepts TLS connections on the gateway port and requires authen
3. Vector search

`$vectorSearch` is an aggregation stage and must be the first stage in the
pipeline — it does not work inside `find()`.
pipeline — it does not work inside `find()`. It also requires a vector index
on the field, or the query fails with
`Similarity index was not found for a vector similarity search query`.

Create the index once:

```python
db.command({
'createIndexes': 'your_collection',
'indexes': [
{
'name': 'embeddings_idx',
'key': {'embeddings': 'cosmosSearch'},
'cosmosSearchOptions': {
'kind': 'vector-ivf',
'numLists': 100,
'similarity': 'COS',
'dimensions': 3
}
}
]
})
```

`dimensions` must match the length of the vectors you store and query. Three keeps
the example short; real embeddings are typically 384, 768, or 1536 wide.

```python
results = collection.aggregate([
Expand Down
4 changes: 2 additions & 2 deletions postgres-api/index.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: Components
description: Learn about pg_documentdb_core, pg_documentdb, and pg_documentdb_gw — the PostgreSQL extensions that enable BSON support, document operations, and MongoDB wire protocol compatibility in Postgres.
description: Learn about pg_documentdb_core, pg_documentdb, and pg_documentdb_gw — the two PostgreSQL extensions and the gateway that enable BSON support, document operations, and MongoDB wire protocol compatibility in Postgres.
---

# Components

The DocumentDB implementation consists of three PostgreSQL extensions that work together to provide MongoDB-compatible document database functionality on top of PostgreSQL.
The DocumentDB implementation consists of two PostgreSQL extensions and a gateway that work together to provide MongoDB-compatible document database functionality on top of PostgreSQL.

## pg_documentdb_core

Expand Down