Skip to content

Commit 1a42351

Browse files
authored
Merge pull request #104 from djsauble/patch-19
Update InsertMany.java
2 parents 530c9ce + 0967758 commit 1a42351

File tree

1 file changed

+14
-21
lines changed
  • astra-db-client/src/test/java/com/dtsx/astra/sdk/documentation

1 file changed

+14
-21
lines changed

astra-db-client/src/test/java/com/dtsx/astra/sdk/documentation/InsertMany.java

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,22 @@
33
import com.dtsx.astra.sdk.AstraDB;
44
import com.dtsx.astra.sdk.AstraDBCollection;
55
import io.stargate.sdk.json.domain.JsonDocument;
6-
76
import java.util.List;
87

98
public class InsertMany {
10-
public static void main(String[] args) {
11-
12-
// Given an active db and a collection with a vector field (see CreateCollection.java)
13-
AstraDB db = new AstraDB("<token>", "<api_endpoint>");
14-
15-
// Create collection if not exists
16-
AstraDBCollection collection = db
17-
.createCollection("collection_vector1",14);
9+
public static void main(String[] args) {
10+
AstraDB db = new AstraDB("<token>", "<api_endpoint>");
11+
AstraDBCollection collection = db.createCollection("collection_vector1",14);
1812

19-
// Insert documents, ids are generated here
20-
List<String> identifiers = collection.insertMany(List.of(
21-
new JsonDocument()
22-
.vector(new float[]{1f, 0f, 1f, 1f, .5f, 1f, 0f, 0.3f, 0f, 0f, 0f, 0f, 0f, 0f})
23-
.put("product_name", "Yet another product")
24-
.put("product_price", 99.99),
25-
new JsonDocument()
26-
.vector(new float[]{1f, 0f, 1f, 1f, .5f, 1f, 0f, 0.3f, 0f, 0f, 0f, 0f, 0f, 0f})
27-
.put("product_name", "product3")
28-
.put("product_price", 99.99)));
29-
30-
}
13+
// Insert documents into the collection (IDs are generated automatically)
14+
List<String> identifiers = collection.insertMany(List.of(
15+
new JsonDocument()
16+
.vector(new float[]{1f, 0f, 1f, 1f, .5f, 1f, 0f, 0.3f, 0f, 0f, 0f, 0f, 0f, 0f})
17+
.put("product_name", "Yet another product")
18+
.put("product_price", 99.99),
19+
new JsonDocument()
20+
.vector(new float[]{1f, 0f, 1f, 1f, .5f, 1f, 0f, 0.3f, 0f, 0f, 0f, 0f, 0f, 0f})
21+
.put("product_name", "product3")
22+
.put("product_price", 99.99)));
23+
}
3124
}

0 commit comments

Comments
 (0)