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
12 changes: 0 additions & 12 deletions getting-started/aws-setup.md

This file was deleted.

22 changes: 0 additions & 22 deletions getting-started/azure-setup.md

This file was deleted.

8 changes: 0 additions & 8 deletions getting-started/gcp-setup.md

This file was deleted.

29 changes: 17 additions & 12 deletions getting-started/mongo-shell-quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,26 @@ Each index above is on a distinct set of keys, which matters: when you don't pas

Note also that a unique index is not sparse unless you say so. Documents that lack the indexed field are all treated as sharing a single "missing" value, so the second such document violates uniqueness. Add `sparse: true` when the field is optional.

To create a vector index on an embedding field, use the `cosmosSearchOptions` index spec accepted by the DocumentDB gateway:
To create a vector index on an embedding field, use `createIndexes` via `runCommand`. The
`cosmosSearchOptions` spec is not accepted through the `createIndex` helper, which fails with
`Index type 'CosmosSearch' was requested, but the 'cosmosSearch' options were not provided.`

```javascript
db.products.createIndex(
{ embedding: "cosmosSearch" },
{
name: "vectorIndex",
cosmosSearchOptions: {
kind: "vector-ivf",
numLists: 100,
similarity: "COS",
dimensions: 3
db.runCommand({
createIndexes: "products",
indexes: [
{
name: "vectorIndex",
key: { embedding: "cosmosSearch" },
cosmosSearchOptions: {
kind: "vector-ivf",
numLists: 100,
similarity: "COS",
dimensions: 3
}
}
}
)
]
})
```

`dimensions` must match the length of the vectors you store and query — a query vector of a different length is rejected. Three is used here only to keep the example short; a real embedding field is typically 384, 768, or 1536 wide, depending on the model.
Expand Down
12 changes: 0 additions & 12 deletions getting-started/mongodb-migration.md

This file was deleted.

72 changes: 23 additions & 49 deletions getting-started/nodejs-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Learn how to set up and use DocumentDB with Node.js using the official MongoDB N

## Prerequisites

- Node.js 14.x or later
- Node.js 20.19 or later (required by the current `mongodb` driver)
- npm or yarn package manager
- DocumentDB installed and running
- Docker installed (if set up is not completed yet)
Expand Down Expand Up @@ -82,62 +82,36 @@ async function connect() {
```

2. Document operations
- Insert operations
- Find operations
- Update operations
- Delete operations

## Working with Promises and Async/Await

1. Promise-based operations
2. Async/await patterns
3. Error handling
4. Connection management

## Advanced Features

1. Bulk operations
2. Aggregation framework
3. Vector search
4. Geospatial queries
5. Change streams
6. Transactions

## Error Handling

1. Connection errors
2. Operation errors
3. Timeout handling
4. Retry strategies

## Best Practices
```javascript
const users = db.collection('users');

1. Connection pooling
2. Query optimization
3. Bulk operations
4. Error handling
5. Security considerations
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' },
]);

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

1. Basic CRUD application
2. REST API with Express
3. Vector search example
4. Real-time applications with change streams
await users.deleteOne({ name: 'Bob Johnson' });
```

## Testing
Always close the client when the process is done:

1. Setting up test environment
2. Unit testing with Jest/Mocha
3. Integration testing
4. Mock testing
```javascript
await client.close();
```

## Deployment
## Beyond CRUD

1. Development setup
2. Production considerations
3. Monitoring and logging
4. Performance optimization
Aggregation pipelines, vector search, geospatial queries and change streams use the
same syntax as the MongoDB shell. See the
[Mongo Shell Quick Start](https://documentdb.io/docs/getting-started/mongo-shell-quickstart/)
for worked examples, and the [API reference](https://documentdb.io/docs/api-reference/)
for the supported operator set.

## Next Steps

Expand Down
68 changes: 30 additions & 38 deletions getting-started/python-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Learn how to set up and use DocumentDB with Python using the official MongoDB Py

## Prerequisites

- Python 3.7+
- Python 3.9 or later (required by PyMongo 4.x)
- pip package manager
- DocumentDB installed and running (see [Pre-built Packages](https://documentdb.io/docs/getting-started/packages/))
- Docker (if DocumentDB is not set up yet)
Expand Down Expand Up @@ -101,11 +101,13 @@ DocumentDB Local accepts TLS connections on the gateway port and requires authen

2. Document operations
```python
from datetime import datetime, timezone

# Insert a single document
collection.insert_one({
'name': 'John Doe',
'email': 'john@example.com',
'created_at': datetime.utcnow()
'created_at': datetime.now(timezone.utc)
})

# Insert multiple documents
Expand Down Expand Up @@ -145,28 +147,26 @@ DocumentDB Local accepts TLS connections on the gateway port and requires authen

2. DateTime
```python
from datetime import datetime
from datetime import datetime, timezone

# Insert with timestamp
collection.insert_one({
'name': 'Event',
'timestamp': datetime.utcnow()
'timestamp': datetime.now(timezone.utc)
})
```

## Advanced Features

1. Bulk operations
```python
# Initialize bulk operations
bulk = collection.initialize_ordered_bulk_op()

# Add operations
bulk.find({'status': 'pending'}).update({'$set': {'status': 'processed'}})
bulk.find({'age': {'$lt': 18}}).delete()

# Execute
result = bulk.execute()
from pymongo import UpdateMany, DeleteMany

result = collection.bulk_write([
UpdateMany({'status': 'pending'}, {'$set': {'status': 'processed'}}),
DeleteMany({'age': {'$lt': 18}}),
])
print(result.modified_count, result.deleted_count)
```

2. Aggregation framework
Expand All @@ -183,40 +183,33 @@ DocumentDB Local accepts TLS connections on the gateway port and requires authen
```

3. Vector search
```python
# Vector similarity search
results = collection.find({
'$vectorSearch': {
'queryVector': [0.1, 0.2, 0.3],
'path': 'embeddings',
'numCandidates': 100,
'limit': 10
}
})
```

4. PostgreSQL Integration
`$vectorSearch` is an aggregation stage and must be the first stage in the
pipeline — it does not work inside `find()`.

```python
# Access PostgreSQL features directly
from documentdb_api import DocumentDB

# Initialize DocumentDB with PostgreSQL support
db = DocumentDB(client)

# Execute SQL queries on BSON documents
result = db.sql_query(
"SELECT jsonb_path_query(data, '$.name') FROM collection WHERE data @? '$.age > 21'"
)
results = collection.aggregate([
{
'$vectorSearch': {
'queryVector': [0.1, 0.2, 0.3],
'path': 'embeddings',
'numCandidates': 100,
'limit': 10
}
}
])
```

## Error Handling

1. Connection errors
```python
from pymongo.errors import ConnectionFailure

try:
client = pymongo.MongoClient(connection_string)
client.admin.command('ping')
except pymongo.errors.ConnectionError as e:
except ConnectionFailure as e:
print(f"Connection error: {e}")
```

Expand Down Expand Up @@ -250,9 +243,8 @@ DocumentDB Local accepts TLS connections on the gateway port and requires authen

3. Proper cleanup
```python
# Always close connections when done
try:
# Your code here
collection.insert_one({'name': 'Example'})
finally:
client.close()
```
Expand Down
Loading